Skip to content

Commit ae341ec

Browse files
Add matrix_mode and matrix functions.
These provide @contextmanager wrappers for glPushMatrix, glPopMatrix and glMatrixMode.
1 parent f46e780 commit ae341ec

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pygly/gl.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,31 @@ def begin( mode ):
7878
yield
7979
glEnd()
8080

81+
@contextmanager
82+
def matrix_mode( mode ):
83+
"""Wraps glMatrixMode in a context manager,
84+
providing the 'with' keyword.
85+
Automatically restores the existing matrix
86+
mode on exit.
87+
88+
For example:
89+
with gl.matrix( GL_MODELVIEW ):
90+
pass
91+
"""
92+
glPushAttrib( GL_MATRIX_MODE )
93+
glMatrixMode( mode )
94+
yield
95+
glPopAttrib()
96+
97+
def matrix( mat ):
98+
"""Wraps glPushMatrix and glPopMatrix in a
99+
context manager, providing the 'with' keyword.
100+
101+
For example:
102+
with gl.matrix( world_matrix ):
103+
pass
104+
"""
105+
glPushMatrix( mat )
106+
yield
107+
glPopMatrix()
81108

0 commit comments

Comments
 (0)