Sign in to follow this  
Silex

problem with multiple viewports

Recommended Posts

I use glViewport to divide the application window into multiple views, then render the scene for each viewport. I make sure to set up the projection matrix for each viewport before rendering anything. The setup is as follows, in the case of a 800x600 window: 1 600x600 viewport on the left 3 200x200 viewports on the right For some reason, the left viewport renders fine, but something is wrong with the smaller ones. The scene is drawn in them, but it isn't "centered" as it should be, as if the smaller viewports were actually larger and continued off screen to the right. I have double-checked the values I send to glViewport and they are correct, so I'm not sure what else could be going wrong. Anyone got ideas?

Share this post


Link to post
Share on other sites
Not that I doubt the correctness of your code, but could you post the code that you're using to set up the viewports (both the glViewport calls and the projection setup)? I can only speculate based on the information you've given, and it sounds like there's a subtle mistake somewhere in the projection setup. :/

Share this post


Link to post
Share on other sites
No, you should doubt the correctness of my code :P

I'll try to post all that is relevant, let me know if I miss anything.

Here is the main drawing loop:

glEnable(GL_SCISSOR_TEST);

for (int i=0;i<num_viewports;i++)
{ glViewport(views[i].dim.x1,views[i].dim.y1,
views[i].dim.x2,views[i].dim.y2);
glScissor(views[i].dim.x1,views[i].dim.y1,
views[i].dim.x2,views[i].dim.y2);
projection(views[i].dim.x2-views[i].dim.x1,
views[i].dim.y2-views[i].dim.y1);

views[i].cam.step(tdelta);

for (int i=0;i<num_obj;i++)
{ glTranslatef(objects[i].pos[0],objects[i].pos[1],objects[i].pos[2]);
render_lib3ds(objects[i].mdl_index);
}
}

glDisable(GL_SCISSOR_TEST);


Here is the projection function:

int engine::projection(int new_width, int new_height)
{ float ratio=(float)width/height;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, ratio, 0.1, 100.0f); //this does it
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


The camera code should work OK, but if what I posted here seems fine then I suppose the problem must lie in the .step function.

Share this post


Link to post
Share on other sites
This
Quote:
Original post by Silex
The scene is drawn in them, but it isn't "centered" as it should be, as if the smaller viewports were actually larger and continued off screen to the right.

and the variable names in this
Quote:
Original post by Silex

glViewport(views[i].dim.x1,views[i].dim.y1, views[i].dim.x2,views[i].dim.y2);


makes me believe you have misunderstood the last two parameters of glViewport. They are the width and height of the viewport, not, as I think you treat them as, end coordinates.

Share this post


Link to post
Share on other sites
Ha!

Yeah, I thought it would be something like that, but as it coincidentally happened to work for the left viewport I didn't think to check viewport calls.

Thanks Bob.

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