-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgltest.py
51 lines (37 loc) · 1.1 KB
/
gltest.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
'''
Renders a blue triangle
'''
import moderngl
import numpy as np
from example_window import Example, run_example
class HelloWorld(Example):
def __init__(self):
self.ctx = moderngl.create_context()
self.prog = self.ctx.program(
vertex_shader='''
#version 330
in vec2 in_vert;
void main() {
gl_Position = vec4(in_vert, 0.0, 1.0);
}
''',
fragment_shader='''
#version 330
out vec4 f_color;
void main() {
f_color = vec4(0.3, 0.5, 1.0, 1.0);
}
''',
)
vertices = np.array([
-1.0, 1.0,
-1.0, -1.0,
1.0, -1.0,
])
self.vbo = self.ctx.buffer(vertices.astype('f4').tobytes())
self.vao = self.ctx.simple_vertex_array(self.prog, self.vbo, 'in_vert')
def render(self):
self.ctx.viewport = self.wnd.viewport
self.ctx.clear(1.0, 1.0, 1.0)
self.vao.render()
run_example(HelloWorld)