PDA

View Full Version : Switching Between Orthographic and Perspective Views



moonwalkercs
10-11-2005, 06:39 PM
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 << "\nIn 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 << "\nIn 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 << "\nIn 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?

john
10-11-2005, 06:57 PM
do you then redraw the screen? Changing the projection matrix won't suddenly change what has already been drawn; you have to repaint the screen to see any new effect.

cheers
John