cannot view perspective?

i make maze program…
it work just fine…
but, i’m facing problem when want to make a perspective view? the code i make is, when pressing button f1, we can look from perspective view… but when i press f1, the perspective view is appear but just a glance… maybe about one second…after that it back to normal view… i put glutpostredisplay but still cannot solve the problem… can you help me…

Hi !

No I cannot help you no one can help you unless you at least post a piece of code that shows what you are trying to do.

I wild guess is that you have code somewhere that setup the projection for you and this code gets called al the time, so when you change the projection this code will change it back for you, sorry, that’s the best I can do without seeing the code.

Mikael

[This message has been edited by mikael_aronsson (edited 08-16-2003).]

this is the code ::

case GLUT_KEY_F1 :
{
//perspective view
glutSetWindow(subWindowLeft);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(11.0f,12.0f,11.0f, 5.0f,0.0f,5.0f, 0.0f,1.0f,0.0f);
glutPostRedisplay();
renderScene(subWindowLeft);

glutSetWindow(subWindowRight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(11.0f,12.0f,11.0f, 5.0f,0.0f,5.0f, 0.0f,1.0f,0.0f);
glutPostRedisplay();
renderScene(subWindowRight);
}
break;
//Aerial view
case GLUT_KEY_F2:
{
glutSetWindow(subWindowLeft);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(5.0f,10.0f,5.0f, 5.0f,0.0f,5.0f,
0.0f,0.0f,-1.0f);
glutPostRedisplay();
renderScene(subWindowLeft);
}
break;

glutSetWindow(subWindowRight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(5.0f,10.0f,5.0f, 5.0f,0.0f,5.0f,
0.0f,0.0f,-1.0f);
glutPostRedisplay();
renderScene(subWindowRight);
}
break;

Hi !

Ok, the problem is that you should not put any rendering code in the keybord callback, just set a variable and call glutPostRedisplay(), then use the variable in your display callback to render in the correct way.

All your rendering code should be placed in the display callback, glutPostRedisplay() will then call that display function a little later (not when you call glutPostRedisplay).

Mikael

[This message has been edited by mikael_aronsson (edited 08-19-2003).]

just set the variable?
that mean i just put variable and then call the glutpostredisplay function…

case GLUT_KEY_F2:
{
glutSetWindow(subWindowLeft);
renderScene();
glutPostRedisplay();
renderScene(subWindowLeft);
}
break;

is it like the code above?

Hi !

No, you cannot put any OpenGL rendering function calls in the keyboard callback, you should instead:

int viewmode = 0;

keyboard_callback()
switch( key) {
case GLUT_KEY_F1:
viewmode = 0;
glutPostRedisplay();
break;
case GLUT_KEY_F2:
videmode = 1;
glutPostRedisplay();
break;
}}

And then in your display callback:

display_callback()
{

if( viewmode == 0)
…set perpsective mode…
else
…set orthographic mode…
// put your rendering code here
}

Mikael

Yeah, this is a common mistake when people dong properly seperate their code. Your rendering sequence should be its own entity. Your keyboard sequence should be its own entity. You want to set a bool that is initially true, that so that when the scene is rendered it evaluates this bool, and if it is true it is rendered w/o perspective calculations. In your keyboard sequence you want to set a line like this

if(F1 is hit)then
{
perspective(bool) = !perspective;
}

that way the next time you go through your render sequence it will do the perspective calculations. Also make sure you initialize your bool in some other segment of code so it does not get reset to the initial value every time you enter a new frame.

Make sense?