PDA

View Full Version : Ortho and perspective = NEED HELP



Bilyboy
04-15-2004, 02:50 PM
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!

04-15-2004, 03:49 PM
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: )

Bilyboy
04-16-2004, 07:28 AM
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

Bilyboy
04-16-2004, 08:29 AM
OK, i found it :) !
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...