Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange artefacts when rendering texture fonts form freetype

Started by Dr Yap Jun 18, 2012 at 6:05 PM 6 replies 3.5k views
Original Post
Dr Yap
Dr Yap

I'm trying to render text in OpenGL using a texture for each glyph rendered from freetype. It works perfectly and renders the character but I am having a bit of trouble with some strange pixels in my textures.

2vcgi1e.png



In that image at the bottom of the d, u and e there is a line of pixels which shouldn't be there. What is stranger is that these are in the middle of the texture as I have padding at the bottom of each where the descender would go.


My texture parameters are the following, I have heard about changing GL_LINEAR to GL_NEAREST for the mip filters but this only makes the artefacts more pixelated so they must be coming from freetype as far as I can see.



[font=lucida sans unicode,lucida grande,sans-serif]


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
[/font]
[font=lucida sans unicode,lucida grande,sans-serif]

Does anyone know a reason and a way to remove this problem?[/font]
[font=lucida sans unicode,lucida grande,sans-serif]

Thanks[/font]

clb
clb
Try using gDEBugger to take a snapshot of the texture in GPU memory, and see what the pixel contents are. I'm using FreeType2 for my fonts, and haven't observed such an artifact. Perhaps there's an off-by-one copying error occurring somewhere in the code, and the texture actually does contain that row of pixels in GPU memory, or you address one line too low?
Dr Yap
Dr Yap
Good suggestion and I like the look of the tool, but it said it won't work on my system (Mac Lion).
Dr Yap
Dr Yap
I rendered the glyph from freetype into bitmaps and on some of the letters I am being given these artefacts:

21b0myp.jpg 15qci9s.jpg


On the bottom row of pixels there are strange white parts which don't connect to the glyph.

clb
clb
Since you haven't posted any code, it's difficult to say where the pixels come from. Perhaps there's a vertical wraparound issue, or some other addressing problem.

If you want to compare, here's the code I use to cache glyphs into a GPU-side texture: https://dl.dropbox.com/u/40949268/code/FTCacheCharacter.cpp
Dr Yap
Dr Yap
I'm just copying the glyph bitmap into a bitmap file, fout is writing to the data part of the bitmap, library font and size have been set previously:
(I know it isn't very neat)


FT_Load_Char(face, c, FT_LOAD_RENDER);
FT_Bitmap bmp = face->glyph->bitmap;
for (GLsizei y = 0; y < bmp.rows; ++y)
{
for (GLsizei x = 0; x < bmp.width; ++x)
{
char p = ((char*)bmp.buffer)[x+((bmp.rows-y)*bmp.width)];
fout.write(&p,1);fout.write(&p,1);fout.write(&p,1);
}
// pad the aiming columns (bmp is a square)
}
// pad the remaining rows
clb
clb
I think you have a off-by-one error in the code. The line

char p = ((char*)bmp.buffer)[x+((bmp.rows-y)*bmp.width)];


looks like it should instead be


char p = ((char*)bmp.buffer)[x+((bmp.rows-1-y)*bmp.width)];
Dr Yap
Dr Yap
My face will remain in the palm of my hand for some time to come. That was indeed the reason, thank you sir.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.