Jump to content



Bug in the freetype openGL tutorial

  • You cannot reply to this topic
2 replies to this topic

#1 paulhankin   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 October 2011 - 07:31 AM

I've just looked at the NeHe freetype tutorial. http://nehe.gamedev....n_opengl/24001/

It's a great tutorial, and I managed to get freetype fonts in my opengl game in no time at all :)

There's a small, but significant problem with the code though! The textures are created as luminance-alpha textures, which is good, but the mistake is that both the luminance _and_ the alpha are set to the value from the glyph bitmap.

This basically produces an image with premultiplied alpha, yet the alpha gets applied once more during rendering -- causing the edges of glyphs to become much more jaggy.
Simply changing the bitmap creation code from:

for(int j = 0; j <height ; j++) {
  for(int i = 0; i < width; i++) {
    expanded_data[2 * (i + j * width)] = expanded_data[2 * (i + j * width) + 1] = 
        (i >= bitmap.width || j >= bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width * j];
  }
}

to:
for(int j = 0; j <height ; j++) {
  for(int i = 0; i < width; i++) {
    expanded_data[2 * (i + j * width)] = 255;
    expanded_data[2 * (i + j * width) + 1] = 
        (i >= bitmap.width || j >= bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width * j];
  }
}
produces a softer, less jaggy image.

Ad:

#2 Caste   Moderators   -  Reputation: 931

Like
0Likes
Like

Posted 24 October 2011 - 09:22 PM

Thanks for the hint! I'll add a note to the tutorial.

Cheers

#3 chderigo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 03 May 2012 - 01:30 PM

First of all: Thanks for this great tutorial, it really kicks ass...Posted Image love it..
(http://nehe.gamedev....n_opengl/24001/)

There's another bug within this code.
a memory leak is caused by the glyph not getting freed!

bugfix: add the line

FT_Done_Glyph(glyph);


to the bottom of the "make_dlist" function.

documentation for FT_Get_Glyph says:

Note that the created FT_Glyph object must be released with FT_Done_Glyph.






We are working on generating results for this topic
PARTNERS