(I think you should bring this up in the OpenGl community; if the with-statement supports the usage I don't see why not. ["GvR"])
OpenGL programmers have complained about using Python because the code indentation doesn't follow the display tree. For an example pulled from one of my (Andrew Dalke) projects
glBegin(GL_QUAD_STRIP) glColor3f(1.0,1.0,1.0) #corner 1 glNormal3f(0.57735027, 0.57735027, 0.57735027) glVertex3f(0.5, 0.5, 0.5) glColor3f(1.0,0.0,1.0) #corner 2 glNormal3f(0.57735027, -0.57735027, 0.57735027) glVertex3f(0.5, -0.5, 0.5) ... glEnd()
Some people write this as some variant of
glBegin(GL_QUAD_STRIP) if 1: glColor3f(1.0,1.0,1.0) #corner 1 glNormal3f(0.57735027, 0.57735027, 0.57735027) glVertex3f(0.5, 0.5, 0.5) glColor3f(1.0,0.0,1.0) #corner 2 glNormal3f(0.57735027, -0.57735027, 0.57735027) glVertex3f(0.5, -0.5, 0.5) ... glEnd()
and sometimes using try/finally so that errors don't cause the gl state to become corrupted.
Would an appropriate use of this proposal be to allow
with QUAD_STRIP: glColor3f(1.0,1.0,1.0) #corner 1 glNormal3f(0.57735027, 0.57735027, 0.57735027) glVertex3f(0.5, 0.5, 0.5) glColor3f(1.0,0.0,1.0) #corner 2 glNormal3f(0.57735027, -0.57735027, 0.57735027) glVertex3f(0.5, -0.5, 0.5) ....
where there are a bunch of small classes for each of the possible glBegins, such as
class QUAD_STRIP: @staticmethod def __enter__(): glBegin(GL_QUAD_STRIP) @staticmethod def __exit__(*args): glEnd()
If so, I rather like that ability as it makes the graphics programmer's intent clearer and prevents problems balancing glBegin and glEnd - even in the face of code errors in the actual code block! -- Andrew Dalke