Ortho and perspective = NEED HELP

Hi all,
Im having some trouble switching from ortho. to perspective… in my humble first-time-using-OpenGL program i have a buttoned menu with mode-switching buttons (among the others)…
When i make the switch to perspective mode it flikers the drawing once…and only when i reshape, move the window or press the ‘perspective button’ it flikers once again…
Now…for both modes im using glutRedisplay. But it seems that it only works for the orthographic projection as i use the same drawing procedure for both.
What doesn’t make sense is i that do see the shapes fliker once, indicating that the perspective parameters are defined OK.
Any ideas may be helpfull!

Thanks!

Maybe you’re making a permanent change to a matrix each frame, but not reverting to either the identity or a known matrix?

glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Do you have this line?
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);

ASide from that, are you sure it is drawing once? It can often be hard to be sure.

Make sure your objects are going to be visible in the perspective. Think about the shapes of the clipping planes, and the position of the eye in each case. You may need to translate your scene backwards to get your objects in-view.

(Damn is the forum software picky these days. Deleted half my post when I used a pipe symbol earlier, and now I find it won’t let me use angle brackets at all, not even HTML-escaped… :mad: )

With or without these lines i have the same result…which is very confusing :confused: !
Ok, here is the code for the ortho-perspective swich:

//----------------------------------------------------------------------------------
// Switch to ortho. projection (Default)
void OnOrtho()
{
	enableOrtho = true;
	enablePerspective = false;
	
	glutSetWindow(wSub1);
	glDepthMask(GL_FALSE);
	glClear(GL_COLOR_BUFFER_BIT);
}
//----------------------------------------------------------------------------------
// Switch to perspective projection
void OnPerspective()
{
	enableOrtho = false;
	enablePerspective = true;
		
	glutSetWindow(wSub1);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glClearDepth(1.0);
}

And here is the display procedure:

void displaySubWin1()
{
	glPushMatrix();

		glColor3f( 1.0 , 0.0 , 0.0 );	

		if(enableAnimation && enableOrtho)
		{
			glOrtho( orthoLeft ,orthoRight, orthoBottom , orthoTop, orthoNear , orthoFar );
			
			glClearColor( 0.0 , 0.0 , 0.0 , 0.0 );
			glClear(GL_COLOR_BUFFER_BIT);
			Animate(0);
		}
		
		if(enableAnimation && enablePerspective)
		{
			gluPerspective(perspectFovy, perspectAspect, perspectNear, perspectFar);

				glColor3f(0.0,1.0,0.0);
						
			Animate(0);
			
		}

	glPopMatrix();
	glFlush();
	glutSwapBuffers();
	glutPostRedisplay();
}

in ‘Animate’ all i do is draw the shapes i want to see

OK, i found it :slight_smile: !
The problem was that i “initialized” the depth buffer and related, only when switching between modes!
Why it worked fine for the ortho. projection?
simply because no depth initialization needed…
however, in perspective mode depth init. is a must!!
The bottom line is to initialize the depth buffer before glPerspective(…) in the display function… (then postRedisplay will do the job also for the perspective projection)

Hope that helped…