Not too long ago I made a thread requesting help with rendering fonts in FreeType. After a while, I got everything to work perfectly and had a pretty good font renderer. The problem that I ignored for a while was that I was making a texture for each glyph, which made the program's memory usage insanely high. Today I decided to just create a single texture instead, and place each glyph in a single section (font atlas). Unfortunately, I'm getting terrible results and haven't figured this out in the past 6 hours I've been working on it.
Above is the result when I draw the entire texture.. I'm not sure exactly why this happens, I am using the same code I was before to rasterize the glyphs into the texture.
case FT_PIXEL_MODE_GRAY:
{
for ( int j = 0; j < glyph_h; j++ )
{
uchar *psrc = bitmap->buffer + ( j * bitmap->pitch );
for ( int i = 0; i < glyph_w; i++ )
{
uchar *pdst = dst + ( 4 * i + j * stride );
*pdst++ = 0xFF;
*pdst++ = 0xFF;
*pdst++ = 0xFF;
*pdst++ = *psrc++;
}
}
break;
}
The only difference is how it is loaded into the buffer (which just adds the position "(y * texture_size) + x")
// dst - a unsigned char buffer
// x/y - the current x/y position in the texture
ft_RenderGlyphToBuffer( dst + ( y * texsize ) + x );
Is my logic or approach wrong here? Appreciate any help, thank you.