I have problems with two viewports. My rendering loop is as follows:
Setup2D();
Render2DScene();
Setup3D();
Render3DScene();
And the setup functions are:
void Setup2D()
{
glViewport (0, 0, window_width/2, window_height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, 0.5*window_width, window_height, 0.0);
}
void Setup3D()
{
float ratio = 0.5*float(window_width)/float(window_height);
glViewport (window_width/2, 0, window_width/2, window_height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective (45.0, ratio, 0.01, 1000.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}
If I omit setting up the last three lines of the Setup3D function, the 2D scene is drawn.
On the other hand, if I render like this:
Setup3D();
Render3DScene();
Setup2D();
Render2DScene();
both viewports display both scenes. Any idea of what I am doing wrong?