About the Projection matrix
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
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);
glLoadIdentity();
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
glLoadMatrixf(projection);
Remember to switch back to the modelview matrix mode when you've done.
To create a new perspective matrix do
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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
glLoadMatrixf(projection);
Remember to switch back to the modelview matrix mode when you've done.
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?
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?
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};
Should be the one:
GLfloat projection[16]={1, 2, 3, 4, 5, 6, 7, ..., 16};
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):
You can use LoadTransposeMatrix() to load a matrix in row major order, ie. your option A (requires an extension though).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement