PDA

View Full Version : gluPerspective Question



Stack Overflow
01-01-2003, 03:02 PM
Is there a way to update gluPerspective by using LoadIdentity or anything else?

Thank You.

- VC6-OGL

Coriolis
01-01-2003, 03:06 PM
gluPerspective effectively makes a matrix from the argument list and then calls glMultMatrix with it. In other words, gluPerspective is not a matrix, it just modifies the active matrix.

Stack Overflow
01-01-2003, 03:53 PM
I am trying to create a camera scene by changing the gluPerspective, for example:



void reshape( int w, int h ) {
h = h < 1 ? 1 : h;
n = 1.0;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glViewport( 0, 0, w, h );

ratio = n * w / h;
gluPerspective( 75.0, ratio, 1.0, 1000.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

So far n = 1, but if I change n from 1 to 2, the perspective view does not update. Why?

- VC6-OGL

[This message has been edited by VC6-OGL (edited 01-01-2003).]

[This message has been edited by VC6-OGL (edited 01-01-2003).]

[This message has been edited by VC6-OGL (edited 01-01-2003).]

[This message has been edited by VC6-OGL (edited 01-01-2003).]

[This message has been edited by VC6-OGL (edited 01-01-2003).]

zed
01-01-2003, 08:56 PM
gluPerspective( 75.0, ratio, 1.0, 1000.0 );
belongs in the modelview not projection

cass
01-01-2003, 10:08 PM
gluPerspective belongs in the PROJECTION matrix.

From your description it looks like changing n *should* have an obvious effect.

Thanks -
Cass

Stack Overflow
01-02-2003, 07:25 AM
Thanx,

I figured out what I was missing.

- VC6-OGL

Devulon
01-02-2003, 07:57 AM
Originally posted by cass:

gluPerspective belongs in the PROJECTION matrix.

From your description it looks like changing n *should* have an obvious effect.

Thanks -
Cass

Come on Cass you know that gluPerspective is completely valid for any matrix mode. Imagine the scene geometry (or texture coords for that matter) taking on perspective !!! Ahhh my head hurts trying to picture that. ( :

Devulon

The only reason I made this post is because I haven't posted anything in a while. Currently occupied with a massive 3dStudio Max Exporter.

Stack Overflow
01-02-2003, 08:05 AM
My Program works just fine if I define gluPerspective in PROJECTION Matrix Mode. What really needs to go in the MODELVIEW Matrix Mode is glTranslatef or gluLookAt, which I have defined in my Display function for camera motion.

- VC6-OGL

Stack Overflow
01-02-2003, 08:15 AM
Now, what I forgot to do before was, glLoadIdentity was not set in my function using 'n', so I could not change Perspective view, but changing float n from 1 to 2 was successful, but it never changed the view as 'n' requested. After using glLoadIdentity, I set n to equal 2 and my Perspective changed. So, using gluPerspective in PROJECTION Matrix Mode does not change the fact of using gluPerspective in MODELVIEW or any other Matrix Mode.

Thank you, Cass.

- VC6-OGL

[This message has been edited by VC6-OGL (edited 01-02-2003).]

Stack Overflow
01-02-2003, 08:28 AM
One more thing, my screen blanks out defining gluPerspective in MODELVIEW Matrix Mode before or after glLoadIdentity, including glOrtho or almost anything besides glTranslatef or gluLookAt.

- VC6-OGL

cass
01-02-2003, 12:38 PM
Originally posted by Devulon:
Come on Cass you know that gluPerspective is completely valid for any matrix mode. Imagine the scene geometry (or texture coords for that matter) taking on perspective !!! Ahhh my head hurts trying to picture that. ( :

Devulon


Certainly gluPerspective is completely valid for any matrix stack. It's used regularly in the texture matrix for projective texture mapping, for example.

What I wanted to make clear is that it's fine (and almost certainly most common) to have gluPerspective in the PROJECTION matrix.

Thanks -
Cass

Stack Overflow
01-02-2003, 01:22 PM
Devulon, you may want to check out the Red Book to refer to the examples. Most of them seem to use glOrtho or gluPerspective in the PROJECTION Matrix Mode. Red Book (http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/)

Chapter 3: Viewing (http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@Generic__BookTextView/6635;cs=fullhtml;pt=6635#X)

- VC6-OGL