PDA

View Full Version : Strange thing happening - This simple teapot is distorted!!!



jojo555
03-13-2004, 01:15 AM
People, i am really baffled. This simple teapot lools distorted and i can't figure out why. And why is that wirecube not drawing? Can u please help me out?
Thanks.


#include <GL/glut.h>
#include <stdlib.h>

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(8.0, 3.0, 8.0, 8.0, 3.0, 0.0, 0.0, 1.0, 0.0);

glColor3f(0.8,0.2,0.1);
glutWireTeapot(2.0);
glTranslatef(5.0, 0.0, 0.0);
glutWireCube(1.0);
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
float aspect = (float)w/(float)h;
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(120.0,aspect,0.0,10.0);
}


int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (700, 450);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

zeckensack
03-13-2004, 02:13 AM
Your gluPerspective call is the culprit.

1)a 120 degrees fov is way too much. 45 degrees would be a good starting point.
2)a near plane at zero isn't allowed, and cannot be allowed. You're lucky that you get anything rendered at all. Bump that up to 1.0. Very small values should be avoided, because they reduce effective depth precision.

jojo555
03-14-2004, 12:35 AM
Hey thanks, but tell me why should changing the FOV distort the image. If i increase the FOV, simply the viewing area that was being mapped to the viewport in now increased, but the aspect is still the same. So a larger part of the scene is now mapped to the same vieport, thereby reducing the size of the same object.
But why should the image distort!!? And then i have seen some applications where the user has the choice to modify FOV. There, this trouble doesn't arise. So how do they do it?

Thanks.

ZbuffeR
03-14-2004, 01:32 AM
Fovs wider than about 70 degrees do show some distortion near the edges. That's because of the projection. You have to put back the camera further and use narrower fov angles.

But what exactly do you mean by 'distortion' ??? Can you be more precise, or give a link to a screenshot of your problem ?

zeckensack
03-14-2004, 12:11 PM
Originally posted by jojo555:
Hey thanks, but tell me why should changing the FOV distort the image. If i increase the FOV, simply the viewing area that was being mapped to the viewport in now increased, but the aspect is still the same. So a larger part of the scene is now mapped to the same vieport, thereby reducing the size of the same object.Not quite. Fov affects the perspective divide. If you construct two projections with different fovs but the same near plane dimensions, objects at the near plane will be the same size, but objects farther away will get smaller "faster" for the version with larger fov. Large fovs produce some sort of fish eye lens effect.

But why should the image distort!!? And then i have seen some applications where the user has the choice to modify FOV. There, this trouble doesn't arise. So how do they do it?

Thanks.It applies to all applications, really. If you have Quake3 installed, try this:
/devmap q3dm1
/cg_fov 170

Extreme distortion is what you'll get. 120 will not as bad, but it's not "normal" either.
It may also be the case that Quake 3 and gluPerspective disagree about how to measure fov. It can be either the angle between the forward axis and the upper clip plane, or it can be the angle between the upper and lower clip planes (the latter would be twice the former). Not sure atm.