problem with multiple viewports

Started by
3 comments, last by Silex 18 years, 10 months ago
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?
Advertisement
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. :/
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.dim.x1,views.dim.y1,                    views.dim.x2,views.dim.y2);        glScissor(views.dim.x1,views.dim.y1,                    views.dim.x2,views.dim.y2);        projection(views.dim.x2-views.dim.x1,                    views.dim.y2-views.dim.y1);                views.cam.step(tdelta);                           for (int i=0;i<num_obj;i++)        {   glTranslatef(objects.pos[0],objects.pos[1],objects.pos[2]);            render_lib3ds(objects.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.
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.dim.x1,views.dim.y1, views.dim.x2,views.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.
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.

This topic is closed to new replies.

Advertisement