How to get projection matrix?

Hi,

glgetdoublev is omitted from OGL ES. How can i immitate its usage??
i would like to get the projection and modelview matrices.

best
Fad

Use glGetFloatv.

But is that available in ES 1.0?? I now it is in ES1.1 only!!

In OpenGL ES 1.0 you have to use the OES_query_matrix extension.


// global scope
typedef GLbitfield (APIENTRY * PFNGLQUERYMATRIXXOES) (GLfixed mantissa[16], GLint exponent[16]);
PFNGLQUERYMATRIXXOES glQueryMatrixxOES;

// your init function
// before this, make sure that "OES_query_matrix" is part of the extension string
glQueryMatrixxOES = (PFNGLQUERYMATRIXXOES) eglGetProcAddress("glQueryMatrixxOES");

// where you want to use it
glMatrixMode(GL_MODELVIEW);
GLfixed mantissa[16];
GLint exponent[16];
GLbitfield validcomponents = glQueryMatrixxOES(mantissa, exponent);

THANX XMAS

Hi (Xmas),

I managed to apply the code you provided me. However, the results in mantisa are too large fixed values (tens of thousends when shifted to integers). what do these values really mean?? an what is the need for epxonent in this case??

cheers

I managed to find a way to get the exact value of the matrix fields. correct me if i am wrong:

matrix[i] = mantisa[i]*2^exponent[i]

Cheers

That is correct. The reason for the separate mantissa and exponent was to enable this extension to return both fixed point and floating point internal representations accurately.

Hi,

I have posted this tread long time ago and i found it useful. However now i am facing a limitation with the usage of the method to retreive the projection and model-view matices.

the code below suggests querying the matrix needed just after loading it:

// global scope
typedef GLbitfield (APIENTRY * PFNGLQUERYMATRIXXOES) (GLfixed mantissa[16], GLint exponent[16]);
PFNGLQUERYMATRIXXOES glQueryMatrixxOES;

// your init function
// before this, make sure that “OES_query_matrix” is part of the extension string
glQueryMatrixxOES = (PFNGLQUERYMATRIXXOES) eglGetProcAddress(“glQueryMatrixxOES”);

// where you want to use it
glMatrixMode(GL_MODELVIEW);
GLfixed mantissa[16];
GLint exponent[16];
GLbitfield validcomponents = glQueryMatrixxOES(mantissa, exponent);

in this case i will be able to query the GL_PROJECTION matrix only once in the init function as it is loaded only then.
How can i query it at any time in the code?

thanx
Fadi

I don’t see where it suggests that. Once you have initialized the function pointer you can use glQueryMatrixxOES anywhere (provided it is declared at global scope).

But again, please check that “OES_query_matrix” can be found in the extension string (and that the pointer returned by eglGetProcAddress is not NULL) before you use the extension.

I have used the function and it did not return NULL. so there is no problem with this :slight_smile:

regarding the suggestion. I should have made myself clearer. in order to load a matrix u use glLoadMatrix(…) with GL_PROJECTION or GL_MODLEVIEW as parameters. then glQueryMatrixxOES will query the matrix just loaded before its call (as in teh code snipet below).

so, if you call glLoadMatrix(GL_PROJECTION); then glQueryMatrixxOES(); you will be able to query the proj matx, and that is possible done only in the Init() function. and if you call glLoadMatrix(GL_MODELVIEW); then glQueryMatrixxOES(); you will be able to query the modelvw matx, and this can be queried everytime as the modelview is the one on top alway.

FC

I’m not sure I understand. Why do you think this only works in the Init function? glLoadMatrix doesn’t take any parameter except the matrix. You can query all matrices at any time, all you have to do is set the right current matrix with glMatrixMode before calling glQueryMatrixxOES.

sorry i mixed up. i meant using glMatrixMode rather than glLoadMatrix.
your explanation makes it clear to me. I thought that i can use glMatrixMode only in the Init func!!! But one question, wouldn’t using glMatrixMode(GL_PROJECTION) cause the projection matrix to be loaded and multiplied by the current matrix, causing a modification in the scene?

i gues the solution for this would be calling glMatrixMode(GL_MODELVIEW) after that. but i just wnat to know what would happen in i do not proceed the projection with a modelview.

thanx
FC

Hi Fadi,

The GL doesn’t know anything about your Init function. All that matters is making GL calls in the right order, from the same thread, but not in which of your functions you call them.

glMatrixMode does not modify the contents of any matrix. It only sets the current matrix mode, i.e. all subsequent GL matrix manipulation calls will affect the selected matrix. Until you call glMatrixMode again with a different value.

So if all your code assumes that the current matrix mode is GL_MODELVIEW, then every time you want to manipulate/query another matrix (projection or texture) you should make sure to set the matrix mode back to GL_MODELVIEW afterwards.

If you don’t do this, all further matrix manipulation calls would affect the projection matrix.

Ok now this makes sence :slight_smile:
thanx so much for ur help
Fad

I don’t see where it suggests that. Once you have initialized the function pointer you can use glQueryMatrixxOES anywhere (provided it is declared at global scope).

But again, please check that “OES_query_matrix” can be found in the extension string (and that the pointer returned by eglGetProcAddress is not NULL) before you use the extension.[/quote]

Hi all!
I’m working on a Dell Axim x51v and I’m trying to use the GL_OES_query_matrix extension. I founded it in the extension string, and I load it the same way as you, but I get a NULL pointer calling the eglGetProcAddress function.

Do you know why could be that?
Thanks a lot in advance.
Roberto

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.