Matrices

I just ran this code, being curious to see OpenGL’s matrix multiplication: main.cpp and I got the following result:

Modelview Identity:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Modelview Translation of 2, 2, 2:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Modelview Scaling of 2, 2, 2:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection Identity:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection glOrtho -2.0, 2.0, -2.0, 2.0, -2.0, 2.0:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Projection glFrustum -2.0, 2.0, -2.0, 2.0, 1.0, 10.0:
Matrix:
7.92252e+33 5.60519e-45 0 0
5.95171e-39 3.21396e-39 3.21401e-39 3.2142e-39
7.92481e+33 7.8354e+33 NaN 7.92252e+33
7.92254e+33 5.95171e-39 3.21405e-39 5.95186e-39

Process returned 0 (0x0) execution time : 0.125 s
Press any key to continue.

Shouldn’t it start with the identity matrix? I have a feeling I made a mistake somewhere.

When you call the OpenGL matrix functions do you have a valid rendering context?

Oh, you’re right. :slight_smile: I knew it would be a silly mistake like that. By the way, why does OpenGL need a valid rendering context for the matrices to make sense?

The OpenGL matrix stack is stored with the context. If you switched rendering contexts and your matrix stack didn’t change accordingly, that could make things rather difficult…

By the way, why does OpenGL need a valid rendering context for the matrices to make sense?

Don’t forget that OpenGL API is a specification so, an OpenGL driver might implement matrix manipulation in hardware (accelerated on the video card) another driver might implement matrix manipulation in software (on the cpu). So the API is not able to perform anything before a valid rendering context is active. This explanation is oversimplified and hope is not wrong.

Thanks for all your answers, I knew there must have been something wrong with values like “5.95171e-39” and “NaN” in an OpenGL matrix.