Browse Source

Fixed Font character placement.

glPrintf now also activates the string.
Thomas Buck 10 years ago
parent
commit
ec2d858b4e
3 changed files with 16 additions and 11 deletions
  1. 4
    0
      src/GLString.cpp
  2. 5
    10
      src/Render.cpp
  3. 7
    1
      src/Texture.cpp

+ 4
- 0
src/GLString.cpp View File

@@ -118,6 +118,10 @@ int GLString::glPrintf(int x, int y, const char *string, ...) {
118 118
     if (_num_string > _num_string_max)
119 119
         return -2;
120 120
 
121
+    // xythobuz 2014.02.23, Activate, so we don't have to call SetString
122
+    // directly after glPrintf, with the same text...
123
+    _string[_num_string].active = true;
124
+
121 125
     // Mongoose 2002.01.01, Assume no longer than 'sz' wide lines
122 126
     //   on first try
123 127
     _string[_num_string].text = new char[sz];

+ 5
- 10
src/Render.cpp View File

@@ -259,10 +259,9 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
259 259
     mString.Init(5);
260 260
 
261 261
     // String 0: OpenRaider version in lower right corner
262
-    mString.Scale(1.00);
262
+    mString.Scale(0.75f);
263 263
     err = mString.glPrintf(mWidth - 15 * strlen(VERSION),
264 264
             mHeight-35, "%s", VERSION);
265
-    mString.SetString(0, "%s", VERSION);
266 265
 
267 266
     if (err)
268 267
     {
@@ -270,9 +269,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
270 269
     }
271 270
 
272 271
     // String 1: Used for FPS in game text output
273
-    mString.Scale(0.75);
272
+    mString.Scale(0.60f);
274 273
     err = mString.glPrintf(8, mHeight - 25, "%s", "                ");
275
-    mString.SetString(1, "%s", "                ");
276 274
 
277 275
     if (err)
278 276
     {
@@ -280,9 +278,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
280 278
     }
281 279
 
282 280
     // String 2: Used for game console
283
-    mString.Scale(1.0);
281
+    mString.Scale(0.75f);
284 282
     err = mString.glPrintf(8, 25, "%s", console);
285
-    mString.SetString(2, "%s", console);
286 283
 
287 284
     if (err)
288 285
     {
@@ -290,9 +287,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
290 287
     }
291 288
 
292 289
     // String 3: Used for one line map select menu
293
-    mString.Scale(1.75);
290
+    mString.Scale(1.25f);
294 291
     err = mString.glPrintf(mWidth/2-235, mHeight/2-24, "%s", menu);
295
-    mString.SetString(3, "%s", menu);
296 292
 
297 293
     if (err)
298 294
     {
@@ -300,9 +296,8 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
300 296
     }
301 297
 
302 298
     // String 4: Used for one line in game text output
303
-    mString.Scale(1.0);
299
+    mString.Scale(0.75f);
304 300
     err = mString.glPrintf(8, 55, "%s", "                    ");
305
-    mString.SetString(4, "%s", "                    ");
306 301
 
307 302
     if (err)
308 303
     {

+ 7
- 1
src/Texture.cpp View File

@@ -320,7 +320,11 @@ gl_font_t *Texture::generateFont(ttf_texture_t *texture)
320 320
             h = 0;
321 321
         }
322 322
 
323
-        h += -texture->fontHeight/2-(texture->fontDescent + texture->glyphs[i].miny);
323
+        // After migrating to SDL2_TTF, some characters where rendered slightly
324
+        // vertically offset. However, dumping the font texture as TGA did not show
325
+        // this offset. It turns out, this fixes the issue...? O.o --xythobuz
326
+        // h += -texture->fontHeight/2-(texture->fontDescent + texture->glyphs[i].miny);
327
+        h -= texture->fontHeight/2 + texture->fontDescent;
324 328
 
325 329
         /* Make a list for this TTF glyph, one nonuniform Quad per glyph */
326 330
         glNewList(font->drawListBase + i, GL_COMPILE);
@@ -405,6 +409,8 @@ ttf_texture_t *Texture::generateFontTexture(const char *filename, int pointSize,
405 409
     int renderStyle = TTF_STYLE_NORMAL;
406 410
     TTF_SetFontStyle(font, renderStyle);
407 411
 
412
+    TTF_SetFontHinting(font, TTF_HINTING_LIGHT);
413
+
408 414
     /* Allocate a new TTF font texture */
409 415
     printf("Creating font texture from '%s'...\n", filename);
410 416
     texture = new ttf_texture_t;

Loading…
Cancel
Save