I\'m implementing a GUI built on top of OpenGL. I came to the problem that each GUI will have -- text rendering. I know of several methods of rendering text in OpenGL, howev
could just use these two functions:
void renderstring2d(char string[], float r, float g, float b, float x, float y)
{
glColor3f(r, g, b);
glRasterPos2f(x, y);
for(unsigned int i = 0; i < strlen(string); i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]);
}
void renderstring3d(char string[], float r, float g, float b, float x, float y, float z)
{
glDisable(GL_LIGHTING);
glColor3f(r, g, b);
glRasterPos3f(x, y, z);
for(unsigned int i = 0; i < strlen(string); i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]);
}
then when you render 2D text, don't forget to reset both the modelview and projection matrices.
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// Render text and quads
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
You don't need to render to a quad using these functions, because these functions render directly to the framebuffer.
And if that doesn't work for you, check this out. http://www.opengl.org/resources/faq/technical/fonts.htm
It talks about rendering text using glBitmap, glDrawPixels, and alpha blending.