The OpenGL documentation say that the gluLookAt() calls should be done on the GL_MODELVIEW matrix:
http://www.opengl.org/resources/faq/technical/viewing.htm
In fact the docs link to an article which say that using gluLookAt() on the GL_PROJECTION matrix is extremly bad:
Help stamp out GL_PROJECTION abuse
On the other hand, there are a lot of tutorials and examples where gluLookAt() is in fact called on the GL_PROJECTION matrix. And at the same time, while the article mentioned above does say to NOT use it on the GL_PROJECTION matrix, it sais that in most such usages there's no visible problem from doing so.
My questions is then: what's the best way to use gluLookAt() in real life projects? Is it really that much of a no no to use it on the GL_PROJECTION matrix?
The gluLookAt() function gives you a transformation matrix that transforms a rotation of an object in your scene. So this is clearly a model transformation and must go into the GL_MODELVIEW matrix.
As for the why, this becomes clearer when you do it yourself in a vertex shader:
While the position of the vertices are indeed just v.pos * modelview * projection
, the modelview matrix is needed without the projection component for other calculations (for example lighting and fog). That's why the fixed function pipeline seperates these two matrices.
So you should stick to the paradigms that are specified in the API and especially never trust any of the myriads of bad opengl "tutorials".
I'm not sure I understand the question. Are you asking why the page tells you not to do something that only works "most" of the time?
It's really not that hard to understand. "Most such usages", by definition, means that there are some such usages do exhibit problems.
So you can either do the thing that will work sometimes and then break other times, or you can do the thing that will always work.
This is not a hard choice. Even moreso since doing it the right way means literally moving one line of code down a couple of lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With