I am trying to use gluOrtho2D with glutBitmapCharacter so that I can render the text on the screen as well as my 3D objects. However, when I use glOrtho2D, my 3D objects disappear; I assume this is because I am not setting the projection back to default for OpenGL / GLUT, but I'm not quite sure what it is.
Anyway, this is the function that I use to render text:
void GlutApplication::RenderString(Point2f point, void* font, string s)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, WindowWidth, 0.0, WindowHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE);
glDisable(GL_TEXTURE_2D);
glRasterPos2f(point.X, point.Y);
for (string::iterator i = s.begin(); i != s.end(); ++i)
{
glutBitmapCharacter(font, *i);
}
glEnable(GL_TEXTURE);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
And, the rendering function is like this:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
glPopMatrix();
Point2f statusPoint(10, 10);
RenderString(statusPoint, GLUT_BITMAP_9_BY_15, "Loading...");
source
share