4
4
.. moduleauthor:: Adam Griffiths <[email protected] >
5
5
'''
6
6
7
+ from contextlib import contextmanager
8
+
7
9
from pyglet .gl import *
8
10
9
11
from pyrr import rectangle
12
14
def set_viewport ( rect ):
13
15
"""Calls glViewport with the dimensions of
14
16
the rectangle
17
+
18
+ This call can be undone by first calling
19
+ glPushAttrib( GL_VIEWPORT_BIT )
20
+ and later calling glPopAttrib().
15
21
"""
16
22
glViewport (
17
23
int (rect [ 0 ][ 0 ]),
@@ -30,6 +36,10 @@ def set_scissor( rect ):
30
36
.. seealso::
31
37
Module :py:mod:`pygly.window`
32
38
Documentation of the :py:mod:`pygly.window` module.
39
+
40
+ This call can be undone by first calling
41
+ glPushAttrib( GL_SCISSOR_BIT )
42
+ and later calling glPopAttrib().
33
43
"""
34
44
glScissor (
35
45
int (rect [ (0 ,0 ) ]),
@@ -38,3 +48,34 @@ def set_scissor( rect ):
38
48
int (rect [ (1 ,1 ) ])
39
49
)
40
50
51
+ @contextmanager
52
+ def attributes ( attributes ):
53
+ """Wraps glPushAttrib and glPopAttrib
54
+ in a context manager, providing the 'with'
55
+ keyword.
56
+
57
+ For example:
58
+ with gl.attributes( GL_VIEWPORT_BIT ):
59
+ glViewport( 0, 0, 100, 100 )
60
+ """
61
+ glPushAttrib ( attributes )
62
+ yield
63
+ glPopAttrib ()
64
+
65
+ @contextmanager
66
+ def begin ( mode ):
67
+ """Wraps glBegin and glEnd in a
68
+ context manager, providing the 'with'
69
+ keyword.
70
+
71
+ For example:
72
+ with gl.begin( GL_TRIANGLES ):
73
+ glVertex2f( 0.0, 0.0 )
74
+ glVertex2f( 0.5, 1.0 )
75
+ glVertex2f( 1.0, 0.0 )
76
+ """
77
+ glBegin ( mode )
78
+ yield
79
+ glEnd ()
80
+
81
+
0 commit comments