Problem with two viewports

Started by
3 comments, last by jocasa 12 years, 6 months ago
Hi!

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?
Advertisement
At first glance I'd say that you should be switching back to GL_MODELVIEW matrix mode in the 2D function.
Thanks, I tried that, but nothing changes.

I have to say that the problem actually is that the 2D scene is not rendered. The 3D is.
Clear some buffers? Try reseting as many states as possible in the start of both functions to see if it starts working?

o3o

Alright!

The problem was that there were 2D renderings before setting the 2D environment, so they were not displayed. Now I moved the setup code up before all rendering functions and the problem is solved. So anyway, the code of my first post works OK, just in case someone find it useful.

This topic is closed to new replies.

Advertisement