2
\$\begingroup\$

I am learning to use FBOs and one of the things that I need to do when rendering something onto user defined FBO, I have to setup the projection, modelview and viewport for it. Once I am done rendering to the FBO, I need to restore these matrices. I found:

glPushAttrib(GL_VIEWPORT_BIT);
glPopAttrib();

to restore the viewport to its old state. Is there a way to restore the projection and modelview matrix to whatever it was earlier ?

Tech: C++/OpenGL

Thanks!

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

There are depricated functions glPushMatrix and glPopMatrix. I'm not sure if you have them in your version of opengl.

You can also very easily use function glGetFloatv. Example

//save matrix
glGetFloatv(GL_PROJECTION_MATRIX, &floatArray[0]);
//set matrix back
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(floatArray);
\$\endgroup\$
6
  • \$\begingroup\$ I have glPushMatrix and Pop matrix. I didn't know they were deprecated! Also, this is a pretty old link, but it was recommended not to use glGetFloatV to retrieve value and set them later on. opengl.org/resources/features/KilgardTechniques/oglpitfall \$\endgroup\$ Feb 21, 2011 at 20:18
  • \$\begingroup\$ It is interesting, but i do not see any glGetFloatV in this article. Can you please specify it? And if you can use glPushMatrix and glPopMatrix is problem solved? \$\endgroup\$
    – Notabene
    Feb 21, 2011 at 20:26
  • \$\begingroup\$ I think that even glPushMatrix and glPopMatrix are depricated, they can be easily used. I don't have any idea how to use it with non-depricated functions. \$\endgroup\$
    – zacharmarz
    Feb 21, 2011 at 20:27
  • 6
    \$\begingroup\$ It's also not recommended to use any Get command. The best you can do is probably to keep and set your matrices by your self. so restore is just another set. The matrix stack in general is also deprecated, the future proof way of setting them is using constants to your vertex program. \$\endgroup\$
    – void
    Feb 22, 2011 at 12:45
  • 1
    \$\begingroup\$ @BlueRaja because the fixed pipeline was removed; to great avail. Perhaps that can be the question of your study; look at why the fixed pipeline was deprecated, and you shall find your answer. \$\endgroup\$ Jun 22, 2011 at 0:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .