Hi everyone,
I am working with a 3D modelling application with a GUI that will allow you to export a selected object to a file. I’ve allowed any glBegin/glEnd block to be selectable by the user.
So my problem is, if exporting the geometry to the file at any given time I am missing whatever state information OpenGL is having. So to render this object in a completely fresh OpenGL state, I need to reload all the appropriate matrices and bits.
So far I have saved the Projection, Modelview, Texture, Colour matrix stacks. What else do I need?
example for anywhere in the code
glBegin(...);
glColor(...);
glNormal(...);
glVertex(...);
...
glEnd();
if (recording)
{
// save opengl state
// psuedo
for each matrix type MT
d = matrix_stack_depth for MT from OGL
while d > 0
save current matrix to X
glPopMatrix();
// restore the OpenGL state
for each matrix type MT
d = matrix_stack_depth for MT from X
while d > 0
glLoadMatrixf( from X );
glPushMatrix();
// what else? glAttrib/glClientAttrib in the same way?
// re-render but to file.
write(glBegin); write(...);
write(glColor); write(...);
write(glNormal); write(...);
write(glVertex); write(...);
...
write(glEnd);
}
I can do the object exporting just fine. But it would be nice if OpenGL had something to extract the current state at any given time. Are there any libraries out there that can do this?