Sign in to follow this  
jocasa

Problem with two viewports

Recommended Posts

Hi!

I have problems with two viewports. My rendering loop is as follows:

[code]
Setup2D();
Render2DScene();

Setup3D();
Render3DScene();
[/code]

And the setup functions are:

[code]
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);
}
[/code]
[code]
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();
}
[/code]

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:

[code]
Setup3D();
Render3DScene();

Setup2D();
Render2DScene();
[/code]

both viewports display both scenes. Any idea of what I am doing wrong?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this