Jump to content
  • Advertisement
Sign in to follow this  
TheGibberingFool

OpenGL Grabbing a Matrix from GL

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Is there any way to retrieve a matrix from OpenGL, by any chance? At the moment I'm using several calls to glMultMatrix to concatenate animation data on the GPU, but I've reached a point where I need to know the contents of it. The glMultMatrix calls are made at various points at initialisation and it would be irritating to have to rewrite a load of it. Also, I'm trying to perform as much as possible on the GPU, for obvious reasons. Obviously I considered removing the many glMultMatrix calls and use my own matrix class on the CPU and pass it around, but that seems not only a waste of time but also messy. If there's no way to do it though I guess that's how it has to be :) Any ideas chaps? Cheers, Peter

Share this post


Link to post
Share on other sites
Advertisement
I have some old docs, so maybe this has changed. But make sure you use glPushMatrix() before your glGetDoublev() call because glGet retrieves the modelview matrix from the top of the matrix stack.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Disgruntled Gamer
I have some old docs, so maybe this has changed. But make sure you use glPushMatrix() before your glGetDoublev() call because glGet retrieves the modelview matrix from the top of the matrix stack.

Hope this helps.
Yes, it gets the current matrix at the top of the modelview matrix stack (or projection, texture, etc depending on what you use for pname) but it doesn't modify it, so pushing and popping is not needed.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Yes, it gets the current matrix at the top of the modelview matrix stack (or projection, texture, etc depending on what you use for pname) but it doesn't modify it, so pushing and popping is not needed.


I wasn't thinking of glPushMatrix() as a way of saving the matrix from being modified. I was doing it to put my current matrix on top of the stack so when I call glGet it gets the matrix on top of the stack which is the one I just pushed there.

This is how I think it works, but I could be wrong.

Share this post


Link to post
Share on other sites
Quote:
Original post by Disgruntled Gamer
I wasn't thinking of glPushMatrix() as a way of saving the matrix from being modified. I was doing it to put my current matrix on top of the stack so when I call glGet it gets the matrix on top of the stack which is the one I just pushed there.

This is how I think it works, but I could be wrong.
The current matrix is already at the top of the stack. glPushMatrix adds a copy of the current matrix to the top of the stack so that there are two identical matrices at the top and just below the top. This lets you alter the matrix at the top (the current matrix) however you want and then you can pop it to get back to the previous matrix. Calling glPushMatrix too many times without associated glPopMatrix calls will produce a GL_STACK_OVERFLOW error, because you are only adding extra matrices to the stack and never removing them so it will eventually fill up.

You can also query OpenGL for the maximum stack depth using glGet* with pname set to one of the GL_MAX_*_STACK_DEPTH constants.

EDIT: So to sum up, the top of the current matrix mode's (ie: GL_MODELVIEW, GL_PROJECTION, etc) stack is always the current matrix. It will be the matrix that is altered by any call to functions such as glRotate*, glMultMatrix*, glFrustum, gluLookAt, etc.

Share this post


Link to post
Share on other sites
Thanks for the clarification Kalidor, I just did a few glGet calls without the glPushMatrix calls and I was getting new versions of my matrix after calls to glRotate of gluLookAt. I just didn't realize there was already a copy of the current matrix on the stack, but it does make sense. And I do know you need to call glPopMatrix for every glPushMatrix or you can overload the stack. Sorry if I caused any confusion in the thread.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!