PDA

View Full Version : help switching between glortho and gluperspective



bogaat
04-09-2000, 08:00 AM
Hello,
I am having a problem switching between these two projection modes. I have two menu options, from which I am to switch between modes. Each menu option calls a function ,for ex.

void draw_ortho(){
//glViewport(0, 0, w, h);//hrm
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(xmin*2.0, xmax*2.0, ymin*2.0, ymax*2.0, zmin*2.0, -zmax*2.0);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}

void draw_perspective(){
//glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40, 1, zmin*2.0, -zmax*2.0);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}

I am new to this and I would greatly appreciate any wisdom that someone could give me. Be well, bogaat ;]

ben
04-09-2000, 08:20 AM
Switching between perspective and orthographic views takes more than just switching the projection matrix. You need to think about the position of the viewing volume with respect to the viewpoint. For instance, if front clipping plane is very close to the camera in perspective mode, what you will have is a camera with a wide field of view. However, in orthographic mode, things will look good.

If you can describe what you are seeing when you switch between ortho and perspective, I can provide better information.

bogaat
04-09-2000, 09:06 AM
Actually when I switch between the two views nothing happens. I believe that I am not using them correctly or not using another call w/ them correctly. When I comment out the ortho and gluperspect lines it does the same thing. So obviously, I am not doing something right. I have a reshape func which uses glOrtho w/ glViewport. You may notice I have commented out the glViewport calls w/in the two functions. Do I need them? I will be working on this all day today, so ANY comments will help http://www.opengl.org/discussion_boards/ubb/smile.gif Thanks again, Bogaat http://www.opengl.org/discussion_boards/ubb/biggrin.gif

bogaat
04-09-2000, 11:48 AM
Ok, so this is my newest failure...ne suggestions?
void reshape(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
switch(flag) {
case 0: {
if (w <= h)
glOrtho(-4.0, 4.0, -4.0 * (GLfloat) h / (GLfloat) w,
4.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-4.0 * (GLfloat) w / (GLfloat) h,
4.0 * (GLfloat) w / (GLfloat) h, -4.0, 4.0, -10.0, 10.0);
}
case 1:
gluPerspective(10, 2, zmin*2.0, -zmax*2.0);
case 2:
glOrtho(xmin*20, xmax*20, ymin*20, ymax*20, zmin*20, -zmax*20);
}
glMatrixMode(GL_MODELVIEW);
}

03-14-2003, 07:26 AM
Bump.. I'm having the same problem when I switch between modes nothing happens.. ARGHH http://www.opengl.org/discussion_boards/ubb/frown.gif

WDA