Hello!
CONTEXT: I'm finishing writing in Cpp a text rendering library based on FreeType2 and OpenGL, and a little problem raised when I was revising the text alignment code.
PROBLEM: When the text is vertically or horizontally centered (or even worse, both), the textures get distorted. Please take a look at the alignment code below:
if ( (hAlign != 0) && (coord[0] != coord[1]) ) {
if ( hAlign == 1 ) {
glTranslatef( (coord[1] - coord[0] - width) / 2.0f, 0.0f, 0.0f );
} else {
glTranslatef( coord[1] - coord[0] - width, 0.0f, 0.0f );
}
}
if ( (vAlign != 0) && (coord[2] != coord[3]) ) {
if ( vAlign == 1 ) {
glTranslatef( 0.0f, (coord[3] - coord[2] - font.height) / 2.0f, 0.0f );
} else {
glTranslatef( 0.0f, coord[3] - coord[2] - font.height, 0.0f );
}
}
CAUSES: As far as I can imagine, the problem is in the second argument passed to glTranslatef. For some reason I can't understand, when this value is not an integer (what is most of time), the textures get distorted. Converting the value to an integer (and converting again to float to avoid compiler warnings) everything seems to work fine (with some precision loss):
glTranslatef( 0.0f, (float)((int)((coord[3] - coord[2] - font.height) / 2.0f)), 0.0f ); // UGLY!!!
And these are the screenshots for the UNROUNDED and ROUNDED values.
QUESTION: Is this an OpenGL "feature" relating to non-integer coordinates? Can you tell me what is going on? Any kind of help is very welcome!
Thanks a lot!
[Edited by - MajinMusashi on September 27, 2005 11:07:47 PM]
|