I am working on a scripting language plugin that allows a user to access the OpenGL 1.1 command set. In addition, all the functions of the gfx native script command set are transparently redirected to the corresponding OpenGL calls. Typically, the user must use a set of OpenGL commands or built-in set of commands for gfx scripting language, which basically contains only your typical 2D-drawing commands, such as DrawLine(), DrawRectangle(), DrawPolygon(), etc.
Under certain conditions, the user may want to mix calls with OpenGL and the built-in gfx command sets. This leads to the fact that my OpenGL implementation built-in commands, such as DrawLine(), DrawRectangle(), DrawPolygon(), etc., have to deal with any condition in which the machine may be in the current OpenGL.
Therefore, my idea was to first save all the state information on the stack, and then prepare a clean OpenGL context, necessary for my implementations of commands like DrawLine(), etc., and then restore the original state. For instance. something like that:
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
glPushMatrix();
....prepare OpenGL context for my needs.... --> problem: see below
....do drawing....
glPopMatrix();
glPopClientAttrib();
glPopAttrib();
Doing this, however, leads to several problems:
glPushAttrib() , , , , . , . , . ( ) glGet().- : OpenGL ? "" OpenGL, , , , . , ...
- , , , , OpenGL gfx. , .
, , : "" OpenGL? "" : , , , , , . , OpenGL- DrawLine() :
1. Save all current state information
2. Restore default state, set up a 2D projection matrix
3. Draw the line
4. Restore all saved state information so that the state is exactly the same as before
-? , , 100% , .