-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlendQuad.py
More file actions
43 lines (32 loc) · 1.18 KB
/
BlendQuad.py
File metadata and controls
43 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from OpenGL.GL import *
import numpy
class BlendQuad:
""" A single 1x1 quad drawn over the screen, for applying a blending map. """
def __init__(self, alpha):
self.alpha = alpha
def initGL(self):
self.alpha.initGL()
# Create a VBO with two triangles to make a unit quad.
verts = [
[0, 1], [1, 0], [1, 1],
[0, 1], [1, 0], [0, 0],
]
verts = numpy.array(verts, dtype = 'float32')
self.vertdata = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.vertdata)
glBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW)
def draw(self):
glPushAttrib(GL_ENABLE_BIT)
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
self.alpha.apply()
glBlendFunc(GL_ZERO, GL_SRC_COLOR)
glEnable(GL_BLEND)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glBindBuffer(GL_ARRAY_BUFFER, self.vertdata)
glVertexPointer(2, GL_FLOAT, 0, None)
glTexCoordPointer(2, GL_FLOAT, 0, None)
glColor3f(1.0, 1.0, 1.0)
glDrawArrays(GL_TRIANGLES, 0, 6)
glPopClientAttrib()
glPopAttrib()