I'd like to create an abstraction in OpenGL of the environment settings(blending, stenciling, depth, etc.) that works like the matrix stack. Push onto the stack, make any changes you need, draw your objects, then pop the stack and go back to the prior settings.
For example, currently you might have drawing code like this:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
//Draw operations
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
But with an environment stack it would look like this:
glPushEnv();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
//Draw operations
glPopEnv();
As I see it there are only 2 ways to do this:
So option 1 is obviously much simpler. But I run into a problem if I'm using other peoples code in that I don't necessarily know what changes it's making to the environement and therefor my data structure would be out of sync. And since the whole point is to have a simple method of ensuring the environment settings are correct, this is not cool.
So my question is, in this context, how do I change the functions that the OpenGL environment functions point to?
OpenGL already contains this functionality. You want glPushAttrib(GL_ALL_ATTRIB_BITS);
and glPopAttrib();
. See http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/pushattrib.html for more.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.