Multiple viewport problem

I need to do multiple viewport, and i followed the tutorial available here to do that… but I failed to get the results i want.
Here’s how i do…
At the reshape function there, I set the glViewport here and set the projection style here too. Then because of the camera position will be changed all the time(as user controling the camera) so i place the gluLookAt at the display function. Then after this gluLookAt, I set my 2nd viewport right after it with the projection style and the gluLookAt for the second viewport…
The results:
No model that I loaded in display in the display window…just…BLACK…

Can someone please…please help me see where is the problem. Thanks very much.

Here’s my code.

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}

winWidth = width;
winHeight = height;

glViewport(0,0,width,height); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,500.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix

}

int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////

//gluLookAt(0,4.0f,150.0f, 0,3,0.0f, 0,1,0);

gluLookAt(objCamera.mPos.x, objCamera.mPos.y, objCamera.mPos.z,
objCamera.mView.x, objCamera.mView.y, objCamera.mView.z,
objCamera.mUp.x, objCamera.mUp.y, objCamera.mUp.z);

// At here, set the second viewport at the right upper part
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(winWidth/2, winHeight/2, winWidth/2, winHeight/2);

glOrtho(0, winWidth, 0, winHeight, -3, 3);;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0.0, 50.0, 50.0, 0.0, 2.5, 50.0, 0.0, 1.0, 0.0);


…}

Thanks~

I need to do multiple viewport, and i followed the tutorial available here to do that… but I failed to get the results i want.
Which tutorial, and what are the results that you want? Do you have multiple contexts/windows, or just a single window divided into multiple viewports?

I see that this forum offers a code tag for neatly organizing posted code. And may I suggest that you post a code snippet that more fully demonstrates your current attempt. Ellipses are not much help. Sorry, it’s just that I’m having trouble deciphering your code.

What’s wrong with your first and second glViewport/glOrtho call? I’m thinking your projection should be set with the width and height of each viewport, not the window – assuming you have one window and multiple viewports :wink:

Opps…sorry…I didn’t realise about the code tag below…I will alert about that next time…and thanks for your advice…

Ya, I only having one window and multiple viewport…
What I plan to do is actually the walkthrough gaming(sth like CS) and I want to do another small window(viewport) which will show the top view of the whole scene and indicate where is the curent location of the user…

What I did is…I actually already did the walkthrough…without the 2nd viewport code…all models and object can loaded in the program and no problem with that…but when I set another viewport…the problem occurs…the display window become black(blank,no models and objects can be shown).

I think is because the glClear wrote in wrong place but I already tried change the code for the whole day but it just still don’t works…Now I want to comfirm my understanding on OpenGL whether it’s wrong or right…

What I know:
we need to place glClear(GL_COLOR_BUFFER_BIT) before the glViewport then after each glViewport need to place the glClear(GL_DEPTH_BUFFER_BIT).

Situation:
The 1st viewport was set at the reshape function, then because the camera position will always change(because 1st person view mode game), therefore the 1st gluLookAt place in the display function. Then I place the 2nd viewport and gluLookAt after the 1st gluLookAt…

Please help me check whether there’s something wrong with my program…Thanks…I tag the code again~sorry about that again.

  
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
{
	if (height==0)										// Prevent A Divide By Zero By
	{
		height=1;										// Making Height Equal One
	}
	
	winWidth = width;
	winHeight = height;

	glViewport(0,0,width,height);						// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,500.0f);

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix

}

int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

	glLoadIdentity();									// Reset The Current Modelview Matrix

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix
	glViewport(0,0,winWidth,winHeight);						// Reset The Current Viewport



	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)winWidth/(GLfloat)winHeight,0.1f,500.0f);

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix


	//gluLookAt(0,4.0f,150.0f, 0,3,0.0f, 0,1,0);

	gluLookAt(objCamera.mPos.x,  objCamera.mPos.y,  objCamera.mPos.z,	
			  objCamera.mView.x, objCamera.mView.y, objCamera.mView.z,	
			  objCamera.mUp.x,   objCamera.mUp.y,   objCamera.mUp.z);
	glClear(GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

// At here, set the second viewport at the right upper part
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glViewport(winWidth/2, winHeight/2, winWidth/2, winHeight/2);

	glOrtho(0, winWidth, 0, winHeight, -50, 50);


	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	gluLookAt(0.0, 50.0, 50.0, 0.0, 2.5, 50.0, 0.0, 1.0, 0.0);
	glClear(GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer


Draw_Grid();
Draw_BoundingBox();	
.......
.......
.......
}