PDA

View Full Version : Orthographic environment mapping



Pody
07-22-2003, 02:58 AM
Is spherical environment mapping supposed to work well with orthographic projection? With a perspective camera all works fine, but when I change to an orthographic camera, the mapping is all messed up. Any tips?
Thanks in advance

Pody
07-22-2003, 06:20 AM
I tried to adjust my cameras and now the environment looks fine.
Now there's a new problem: when I switch the scene to orthographic mode, the object (i.e. teapot) is strangely clipped.
The functions that set the perspective and orthographic mode are the following:

void perspective() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluLookAt(0, 0, 0, 0, 0, -100, 0, 1, 0);
glFrustum(-1, 1, -1, 1, 0, 10);

glMatrixMode(GL_MODELVIEW);
}

void orthographic(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluLookAt(0, 0, 0, 0, 0, -100, 0, 1, 0);
glOrtho(-1, 1, -1, 1, 0, 10);

glMatrixMode(GL_MODELVIEW);
}

They both use the same view-volume values, so they should both work ok.
Perspective mode works fine, while orthographic mode clips the teapot very oddly! What am I doin' wrong?

errno
07-22-2003, 06:41 AM
you can't set a near plane to 0 for frustum mode.

your matrix use is not very common. you should put all your perspective operations in the projection matrix and all the viewing operations in the modelview matrix.

glFrustum/glOrtho -> GL_PROJECTION
gluLookAt/glTranslate/glrotate -> GL_MODELVIEW

that avoids doing many errors http://www.opengl.org/discussion_boards/ubb/biggrin.gif (like the one you've made).
your matrix operations are in reverse order.

you should have:



void perspective() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glFrustum(-1, 1, -1, 1, 0.1, 10);

glMatrixMode(GL_MODELVIEW);
}

void orthographic(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-1, 1, -1, 1, 0, 10);

glMatrixMode(GL_MODELVIEW);
}

void render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(0, 0, 0, 0, 0, -100, 0, 1, 0);

// render the teapot at the right place
}

Pody
07-22-2003, 07:01 AM
Thanks a lot, that solved my problem!
http://www.opengl.org/discussion_boards/ubb/smile.gif
Bye