Jump to content
  • Advertisement
Sign in to follow this  
jocasa

Problem with two viewports

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!