• 11
• 11
• 12
• 10
• 11

# Problem with two viewports

This topic is 2390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
At first glance I'd say that you should be switching back to GL_MODELVIEW matrix mode in the 2D function.

##### Share on other sites
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.

##### Share on other sites
Clear some buffers? Try reseting as many states as possible in the start of both functions to see if it starts working?