PDA

View Full Version : Viewport Question



12-19-2004, 02:49 PM
OpenGL Experts,
I am trying to get better at understanding
how Viewports work in OpenGL.

I initialized my window like this:


glutInitWindowSize(800,400);I am basically trying to view two red squares in two seperate viewports side by side. Only the first square that is drawn is drawn how I want it to be.

Thanks,
Nick


void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);

//Draw in first viewport
glViewport(0,0,400,400);
glOrtho(-10,10,-10,10,-10,10);
glColor3f(1.0f,0.0f,0.0f);
glRectf(0.0f,0.0f,10.0f,-10.0f);

//draw in second viewport
glViewport(400,0,800,400);
glOrtho(-10,10,-10,10,-10,10);
glColor3f(1.0f,0.0,0.0f);
glRectf(0.0f,0.0f,10.0f,-10.0f);
glFlush();
}

MikeC
12-19-2004, 04:10 PM
glOrtho, like all the matrix functions, multiplies the current matrix - in this case, by an orthographic projection matrix. You're currently multiplying two such matrices together. You probably want to call glLoadIdentity before the second glOrtho. I'm assuming you already have a glMatrixMode call somewhere. I normally write longer sentences than this. Hmm.

hth
Mike

12-19-2004, 06:15 PM
Mike,
Yes it did help...
Looks like I will need to take a quick refresher on how the OGL commands I use reflect matrix operations.

I appreciate your help,
Nick