-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquad.py
64 lines (51 loc) · 1.61 KB
/
quad.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import numpy
import moderngl
from demosys.opengl.vao import VAO
def quad_fs() -> VAO:
"""
Creates a screen aligned quad using two triangles with normals and texture coordiantes.
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance.
"""
return quad_2d(2.0, 2.0, 0.0, 0.0)
def quad_2d(width, height, xpos=0.0, ypos=0.0) -> VAO:
"""
Creates a 2D quad VAO using 2 triangles with normals and texture coordinates.
Args:
width (float): Width of the quad
height (float): Height of the quad
Keyword Args:
xpos (float): Center position x
ypos (float): Center position y
Returns:
A :py:class:`demosys.opengl.vao.VAO` instance.
"""
pos = numpy.array([
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos - width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos - width / 2.0, ypos + height / 2.0, 0.0,
xpos + width / 2.0, ypos - height / 2.0, 0.0,
xpos + width / 2.0, ypos + height / 2.0, 0.0,
], dtype=numpy.float32)
normals = numpy.array([
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
], dtype=numpy.float32)
uvs = numpy.array([
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 0.0,
1.0, 1.0,
], dtype=numpy.float32)
vao = VAO("geometry:quad", mode=moderngl.TRIANGLES)
vao.buffer(pos, '3f', ["in_position"])
vao.buffer(normals, '3f', ["in_normal"])
vao.buffer(uvs, '2f', ["in_uv"])
return vao