How can I generate a view or projection matrix for OpenGL 3.+

Posted by Ken on Game Development See other posts from Game Development or by Ken
Published on 2012-11-23T11:50:58Z Indexed on 2012/11/23 17:20 UTC
Read the original article Hit count: 347

Filed under:
|

I'm transitioning from OpenGL 2 to OpenGL 3.+ and to GLSL 1.5. I'm trying to avoid using the deprecated features.

My question how do we now generate the view or projection matrix. I was using the matrix stack to calculate the projection matrix for me;

GLfloat ptr[16]; 
gluPerspective(...);
glGetFloatv(GL_MODELVIEW_MATRIX, ptr); 
//then pass ptr via a uniform to the shader

But obviously the matrix stack is deprecated. So this approach is not the best an option going forward.

I have the 'Red Book', 7th ed, which covers 3.0 & 3.1 and it still uses the deprecated matrix functions in it's examples.

I could write some utility-code myself to generate the matrices. But I don't want to re-invent this particular wheel, especially when this functionality is required for every 3D graphics program.

What is the accepted way to generate world,view & projection matrices for OpenGL? Is there an emerging 'standard' library for this? Or is there some other hidden (to me) functionality in OpenGL/GLSL which I have overlooked?

© Game Development or respective owner

Related posts about opengl

Related posts about matrix