Jump to content
  • Advertisement
Sign in to follow this  
Dr Yap

OpenGL Strange artefacts when rendering texture fonts form freetype

This topic is 2221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


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

Share this post


Link to post
Share on other sites
Good suggestion and I like the look of the tool, but it said it won't work on my system (Mac Lion).

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:

21b0myp.jpg 15qci9s.jpg


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

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)


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

Share this post


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!