title: How to keep track of OpenGL state across function calls?
body: <p>Since OpenGL is a state machine, I am constantly glEnable() and glDisable()-ing things in my program. There are a select few calls that I make only at the beginning (such as glClearColor) but most others I flip on and off (like lighting, depending on if I'm rendering a model or 3d text or the gui).</p>
  
  <p>How do you keep track of what state things in? Do you constantly set/reset these things at the top of each function? Isn't that a lot of unnecessary overhead?</p>
  
  <p>For example, when I write a new function, sometimes I know what state things will be in when the function is called, and I leave out glEnable or glDisable or other related state-switching calls at the top of the function. Other times, I'm just writing the function in advance and I add in these sorts of things. So my functions end up being very messy, some of them modifying OpenGL state and others just making assumptions (that are later broken, and then I have to go back and figure out why something turned yellow or why another thing is upside down, etc.).</p>
  
  <p>How do you keep track of OpenGL across functions in an object oriented environment?</p>
  
  <hr>
  
  <p>Also related to this question, is how to know when to use push and pop, and when to just set the value.</p>
  
  <p>For example, let's say you have a program that draws some 3D stuff, then draws some 2D stuff. Obviously the projection matrix is different in each case. So do you: </p>
  
  <ol>
  <li>set up a 3d projection matrix, draw 3D, set up a 2d projection matrix, draw 2d, loop</li>
  <li>set up a 3d projection matrix at the program; then draw 3d, push matrix, draw 2d, pop matrix, loop</li>
  </ol>
  
  <p>And why?</p>