Ohad
Ohad

Reputation: 1631

modelview and projection - which code is more common?

1.which code is more common and why? 2. How will you describe the meaning of this code?

A.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluLookAt(1,1,1,0,0,0,1,1,0);

B.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1,1,1,0,0,0,1,1,0);

Upvotes: 0

Views: 46

Answers (1)

genpfault
genpfault

Reputation: 52083

B. It correctly separates the modelview/"camera"-type transforms from the projection matrix.

There are some concerns with putting "camera"-type transforms in the projection matrix:

  • Lighting: OpenGL has to transform vertex normals into world coordinate space - that is to say WITHOUT the effects of perspective - but WITH the effects of the camera position. Hence, only the GL_MODELVIEW matrix is applied to the normals for lighting. If you put the camera transform into the GL_PROJECTION matrix then your lighting will be wrong. However, some people do their own lighting - and in any case, it can be a subtle error that you might not have noticed previously.
  • Fog: OpenGL has to figure out how far each vertex is from the camera. Once again, perspective effects are not relevent to this calculation - so the GL_PROJECTION matrix is not used. If you put the camera transform into the GL_PROJECTION matrix then your fogging will be wrong. Since few people use fog, many people have the error and don't know it.
  • TexGen: Since OpenGL uses the eyepoint to figure out some of the TexGen'ed texture coordinates, if the camera position is all mixed up with the projection information then you'll end up with some pretty strange texture coordinates. (Thanks to Brian Sharp at 3Dfx for pointing this one out)

Upvotes: 2

Related Questions