Multiple Views?

Hey, I’m working on a project where I want to display the same scene four times from different angles, all in one window. Here’s the code I wrote:


//x view
glViewport(0, 0, (winw / 2), (winh / 2));
glLoadIdentity();
gluLookAt(100, 0, 0, 0, 0, 0, 0, 1, 0);
Draw();

//z view
glViewport(0, (winh / 2), (winw / 2), (winh / 2));
glLoadIdentity();
gluLookAt(0, 0, 100, 0, 0, 0, 0, 1, 0);
Draw();

//y view
glViewport((winw / 2), 0, (winw / 2), (winh / 2));
glLoadIdentity();
gluLookAt(0, 100, 0, 0, 0, 0, 0, 1, 0);
Draw();

//movable view
glViewport((winw / 2), (winh / 2), (winw / 2), (winh / 2));
glLoadIdentity();
gluLookAt(0, 0, 0, 0, 0, 0, 0, 1, 0);
Draw();

When I run this it looks like it tries to display all the views, but they flicker on and off. What’s the problem?

You need to understand the parameters you pass on to gluLookat.
You’ll get weird/undefined results if:

  1. eye equals center. (movable view)
  2. eye-center is parallel to UP. (y view)

N.

Okay, I think I have the parameters right now, but they still keep flickering. It’s strange because the first box in the sequence doesn’t flicker at all, the second only flickers a little, the third flickers a lot, and the fourth flickers even more. What could be the cause of that?

Can you post your Draw(); code?
Are you sure this isn’t a double buffer/vsync issue?

N.

Okay, it might look a little sloppy but here’s my Draw() code:


void Bounce::Draw()
{
	//Draw border
	glColor3f(0.0f, 0.0f, 0.5f);
	glRectf(-200, -200, 200, 200);

	//Draw the box
	glColor3f(0.0f, 0.0f, 0.0f);
	glRectf(-100, -100, 100, 100);

	//Draw the lines
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_LINES);
	glVertex3f(-200, 0, 0);
	glVertex3f(200, 0, 0);
	glVertex3f(0, -200, 0);
	glVertex3f(0, 200, 0);

	for (int c1 = 200; c1 > -201; c1 = c1 - 25)
	{
		glVertex3f(c1, -5, 0);
		glVertex3f(c1, 5, 0);
	}

	for (int c2 = 200; c2 > -201; c2 = c2 - 25)
	{
		glVertex3f(-5, c2, 0);
		glVertex3f(5, c2, 0);
	}
	glEnd();

	//Draw the teapot
	glColor3f(0.0f, 1.0f, 0.0f);
	glutWireTeapot(rsize);

        //Select color
	if (colorcount == 6)
		colorcount = 0;
	if (colorcount == 0)
		glColor3f(1.0f, 0.0f, 0.0f);
	if (colorcount == 1)
		glColor3f(0.8f, 0.0f, 0.0f);
	if (colorcount == 2)
		glColor3f(0.7f, 0.0f, 0.0f);
	if (colorcount == 3)
		glColor3f(0.5f, 0.0f, 0.0f);
	if (colorcount == 4)
		glColor3f(0.4f, 0.0f, 0.0f);
	if (colorcount == 5)
		glColor3f(0.3f, 0.0f, 0.0f);

	// Draw a filled rectangle with current color
	glRectf(x, y, x + rsize, y - rsize);

        // Flush drawing commands and swap
        glutSwapBuffers();
}

There’s your problem.
Don’t put the glutSwapBuffers() command in the Draw() call. Just call it once when you finished drawing to all of the 4 viewports.

N.

Okay, now everything works. Thanks for the help!