Sign in to follow this  
Dr Yap

OpenGL Strange artefacts when rendering texture fonts form freetype

Recommended Posts

[size=3]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.[/size]

[center][size=3][img]http://i50.tinypic.com/2vcgi1e.png[/img][/size][/center]

[left][size=3]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.[/size][/left]
[left][size=3]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.[/size][/left]

[font=lucida sans unicode,lucida grande,sans-serif][size=3][CODE]
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);
[/CODE][/size][/font]
[font=lucida sans unicode,lucida grande,sans-serif][size=3]Does anyone know a reason and a way to remove this problem?[/size][/font]
[font=lucida sans unicode,lucida grande,sans-serif][size=3]Thanks[/size][/font]

Share this post


Link to post
Share on other sites
Try using [url="http://www.gremedy.com/"]gDEBugger[/url] 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?

Share this post


Link to post
Share on other sites
I rendered the glyph from freetype into bitmaps and on some of the letters I am being given these artefacts:

[center][img]http://i45.tinypic.com/21b0myp.jpg[/img] [img]http://i46.tinypic.com/15qci9s.jpg[/img][/center]
[left]On the bottom row of pixels there are strange white parts which don't connect to the glyph.[/left]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

[CODE]
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
[/CODE]

Share this post


Link to post
Share on other sites
I think you have a off-by-one error in the code. The line
[CODE]
char p = ((char*)bmp.buffer)[x+((bmp.rows-y)*bmp.width)];
[/CODE]

looks like it should instead be

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

Share this post


Link to post
Share on other sites
My face will remain in the palm of my hand for some time to come. That was indeed the reason, thank you sir.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this