PDA

View Full Version : Reshape Progblens with two Viewports



Legolas
01-18-2002, 01:22 PM
Hi,

I'd like to draw a funny windmill into a GlutWindow. I have set up two Viewports to project two diffent viewangels of the mill, and all looks fine. But only the second Viewport will draw correctly. I do not know why!

Here is a part of my coding:

void reshape (int w, int h)
{

int x = 0;
if (w<h)
x = (w/2);
else
if (w<(2*h))
x = (w/2);
else
x = h;

glViewport(0,0,(GLsizei)x, (GLsizei)x);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,1.0,0.1,150);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,10.0,zoom,
0.0,10.0,0.0,
0.0,1.0,0.0);
display();

glViewport(x + 5,1,(GLsizei)x, (GLsizei)x);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,1.0,0.1,150);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,10.0,zoom,
0.0,10.0,0.0,
0.0,1.0,0.0);
glRotatef(90, 0, 1, 0);
display();

}

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

and

glutSwapBuffers();
glFlush();

will called at the display()function.

Please help me to solve my mistakes
Thanks!

Furrage
01-21-2002, 11:06 AM
Does glClear(GL_COLOR_BUFFER_BIT) clear only the viewport, or does it clear the entire window? If it does the latter then you're clearing the image drawn in viewport 1 when you draw viewport 2. Maybe one of the experts could say more... otherwise you're going to have to experiment.

thebamaman
01-21-2002, 12:01 PM
I do know that the glClear will clear the entire buffer, so that is why your first viewport is not getting drawn. And I would imagine that glutSwapBuffers does the same. So try only one call of glClear and one call of glutSwapBuffers. Unless you want to use the stencil buffer, but I don't think you need that.