# About the Projection matrix

This topic is 4353 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! someone can explain me what does establish the Projection matrix? and how can i modify it or create a new one? Is there any direct relation between the Projection matrix and the frustum that can create glOrtho o gluPerspective? Thanks

##### Share on other sites
There is a direct relation between glOrtho and gluPerspective to the perspective matrix. See the bottom of this page.

To create a new perspective matrix do

glMatrixMode(GL_PROJECTION);

folowed by glOrtho() or gluPerspective().

If you want to modify the projection matrix you must read it back

GLfloat projection[16];
glGetFloatv(GL_PROJECTION_MATRIX, projection);

modify the array (advanced stuff....) then write it back to the projection matrix

Remember to switch back to the modelview matrix mode when you've done.

##### Share on other sites
thanks coordz

but for example if i want to load this matrix:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

How should i write this line?:

GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

or

GLfloat projection[16]={1, 5, 9, 13, 2, 6, ....16};

or what way?

##### Share on other sites
I can't think of any reason why the OpenGL makers would have choosen option B for storing arrays..

Should be the one:
GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

##### Share on other sites
It's option B. OpenGL uses column-major matrices. So this array:

GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};

will yield the following Matrix (in standard mathematical notation):
1  5  9  132  6  10 143  7  11 154  8  12 16

You can use LoadTransposeMatrix() to load a matrix in row major order, ie. your option A (requires an extension though).

##### Share on other sites
Haha!
Well.. this would explain a couple of problems I've been having! :D

##### Share on other sites
As usual Yann L to save the day!

1. 1
Rutin
25
2. 2
3. 3
JoeJ
19
4. 4
5. 5

• 10
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631753
• Total Posts
3002098
×