I am trying to enable my program to switch between orthographic and perspective modes. Here’s my code:
void reshape(int w, int h){
cout << "
In Reshape";
if(h == 0)
h = 1;
float ratio = 1.0* (float)w / (float)h;
float ratio1 = 1.0* (float)h / (float)w;
ww=w; wh=h;
if(orthographic){
cout << "
In Ortho";
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
if(w<=h){
glOrtho((-10), 4, ratio1*(-5), ratio1*9, 2, 20);
}
else{
glOrtho(ratio*(-10), ratio*4, (-5), 9, 2, 20);
}
glMatrixMode(GL_MODELVIEW);
}
if(perspective){
cout << "
In Persp";
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(90, ratio, 1, 30);
glMatrixMode(GL_MODELVIEW);
}
}
nothing happens when i call reshape and want the switches to be made. is there another way to do this?