I have a game engine that uses OpenGL for display.
I coded a small menu for it, and then I noticed something odd after rendering the text.
http://img43.imageshack.us/i/garbagen.png/
As you see, the font is somewhat unreadable, but the lower parts (like “Tests”) look as intended.
Seems the position on the screen affects readability, as the edges get cut.
The font is 9×5, a value that I divide by 2 to obtain width/height and render the object from the center.
So, with 4.5×2.5 pixels (I use floats for x, y, width and height of simple rectangles), the texture is messed up if rendered somewhere other than x.5 or so. However, it only does so in two computers for now, but I would dislike this error to come out since it makes text unreadable. I can make it 4.55×2.55 (by adding a bit of extra size when dividing by 2), and then it renders adequately in all machines (or at least doesn’t happen as often in the problematic two), but I fear this is a hack too gross to keep it and doesn’t solve the issue entirely, and it might scale the text up making the font look…”fat”.
So my question is…is there any way I can prevent this, and not exchanging those values to integers? (I need the slight differences floats offers in comparison). Can I find out which width/heights are divisible by two, and those that aren’t, handle them differently? If it’s indeed a video card issue, would it be possible to circumvent it?
Sorry if there’s anything lacking for the question, I don’t resort to questioning the internet often and I have no coding studies. I’ll be happy to provide any line or chunk of code that might be required.
If you have to draw your text at non-integer coordinates, you should enable texture filtering. Use glTexParameterfv to set
GL_TEXTURE_MIN_FILTERandGL_TEXTURE_MAG_FILTERtoGL_LINEAR. Your text will be blurred, but that cannot be avoided without resorting to pixel perfect (=integer) coordinates.Note that your 0.05 workaround does nothing but change the way the effective coordinates are rounded to integers. When using
GL_NEARESTtexture filtering, there’s no such thing as a half pixel offset. Even if you specify these coordinates, the texture filter will round them for you. You just push it in the right direction with the additional 0.05.