PDA

View Full Version : Problem with OpenGL Superbible example (solved)



shapeare
09-21-2011, 02:36 AM
This book uses a library named GLTools in all of its example code.

The book emphasizes that matrices are stored in column major(check the GLTools source code), but in its code examples, when calling glUniformMatrix4fv,
for example


glUniformMatrix4fv(locMVP, 1, GL_FALSE,
lightTransformPipeline.GetModelViewProjectionMatri x());

the third parameter is always false, which means the matrices it provides are in row major, which is contrary to what they said about their matrices, but it works.

Why?

Dan Bartlett
09-21-2011, 02:48 AM
If you read http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml it states:
If transpose is GL_FALSE, each matrix is assumed to be supplied in column major order. If transpose is GL_TRUE, each matrix is assumed to be supplied in row major order.

See http://www.opengl.org/resources/faq/technical/transformations.htm which also points you to the 2.1 spec, where the relevant section is:


LoadMatrix takes a pointer to a 4 4 matrix stored in column-major order as 16
consecutive floating-point values, i.e. as


[ a1 a5 a9 a13 ]
[ a2 a6 a10 a14 ]
[ a3 a7 a11 a15 ]
[ a4 a8 a12 a16 ]

This differs from the standard row-major C ordering for matrix elements. If the
standard ordering is used, all of the subsequent transformation equations are transposed,
and the columns representing vectors become rows.)
I don't think that later versions of the OpenGL spec state this as clearly, since the documentation for LoadMatrix has gone, but this bit of advice hasn't been put anywhere else.

shapeare
09-21-2011, 03:02 AM
Thank you very much.

I should have checked the specification first.