PDA

View Full Version : Text Rendering



08-18-2003, 05:58 AM
Help Please! I'm trying to convert a True Type Font in a manner that it will render. I can get it to render and it looks very good but then everything else disappears. Its like its on its own plane that comes to the front and hides everything else. I suspect that one of the OpenGL functions I'm calling changes something and it doesn't get reverted back to what it was. Can anyone who knows way more than me help in this matter? I'm very inexperienced with OpenGL so please go easy on the terminology if replying. Thanks!

nexusone
08-18-2003, 07:28 AM
Really not enought information to go on, would have to see your code for drawing the scene.


Originally posted by LostInSpace:
Help Please! I'm trying to convert a True Type Font in a manner that it will render. I can get it to render and it looks very good but then everything else disappears. Its like its on its own plane that comes to the front and hides everything else. I suspect that one of the OpenGL functions I'm calling changes something and it doesn't get reverted back to what it was. Can anyone who knows way more than me help in this matter? I'm very inexperienced with OpenGL so please go easy on the terminology if replying. Thanks!

yaro_dup1
08-18-2003, 08:55 AM
Sounds like something wrong with projection matrix, but code is necessary.

08-19-2003, 01:15 PM
OK...A .TTF file is converted to textured mapping of a ad hoc format (vertically reversed) and placed into a file. This file also contains width, height, border, format, etc. The file is then read to create the texture with the following section of code:

GLubyte * pTexels = (GLubyte *)pFile + pFile->uImageDataOffset;

glGenTextures(1, &TextureName[0]);
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, TextureName[0]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D( GL_TEXTURE_2D,
0,
2,
512,//texture width
512,//texture height
0,
GL_LUMINANCE, // pFile->uDataFormat,
pFile->uDataType,
NULL );
glTexSubImage2D( GL_TEXTURE_2D,
0,
0,
0,
pFile->uWidth,
pFile->uHeight,
GL_LUMINANCE, // pFile->uDataFormat,
pFile->uDataType,
pTexels );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);


Afterwhich each character is placed into a list like my example of an 'M':
//ASCII 77 'M' Begin
glNewList(startIndex + 77, GL_COMPILE);
{
glBegin( GL_POLYGON );
glTexCoord2f( 0.000000f, 0.439453f );
glVertex2f( 0.065614f, 0.834384f );
glTexCoord2f( 0.039063f, 0.439453f );
glVertex2f( 0.634384f, 0.834384f );
glTexCoord2f( 0.039063f, 0.380859f );
glVertex2f( 0.634384f, -0.014386f );
glTexCoord2f( 0.000000f, 0.380859f );
glVertex2f( 0.065614f, -0.014386f );
glEnd();
glTranslatef(0.619998f, 0, 0);
}
glEndList();
//ASCII 77 'M' End


From here each time I want to draw text I call a function that basically steps through the string and calls the appropriate list to render the text. I suspect it is something in the calls of glTexImage2D(); and glTexSubImage2D(); but do no know enough about OpenGL to investigate further.

BlueJ
08-20-2003, 01:50 PM
If you render a normal polygon and then render another polygon with the same coordinates but with an alpha texture, the first poly will just be rendered over. You have to offset the second polygon on its relative z axis.

That's a problem/solution I ran into... if someone could tell me a better way to deal with it I'd appreciate it.

08-21-2003, 06:30 AM
PROBLEM SOLVED! The problem was that texturing was enabled with a call to glEnable(GL_TEXTURE_2D). Then when all of the other objects were rendered, OpenGL would try to render them as textured items but since textures were not created for them they would render as "black holes". I resolved the issue by only enabling texturing when outputting text then disabling it so that all other object would render as pollys.

Thanks to all who supported me in this issue!