I'm trying to use gluOrtho2D with glutBitmapCharacter so that I can render text on the screen as well as my 3D objects. However, when I use glOrtho2D, my 3D objects dissapear; I assume this is because I'm not setting the projection back to the OpenGL/GLUT default, but I'm not really sure what that is.
Anyway, this is the function I'm using 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 render function is similar to this:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glLoadIdentity();
// Do some translation here.
// Draw some 3D objects.
glPopMatrix();
// For some reason, this stops the above from being rendered,
// where the camera is facing (I assume they are still being rendered).
Point2f statusPoint(10, 10);
RenderString(statusPoint, GLUT_BITMAP_9_BY_15, "Loading...");