/
test1_basic_geometry.py
60 lines (54 loc) · 1.26 KB
/
test1_basic_geometry.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
from OpenGLContext import testingcontext
BaseContext = testingcontext.getInteractive()
from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGLContext.arrays import *
from OpenGL.GL import shaders
class TestContext(BaseContext):
"""Creates a simple vertex shader ..."""
def OnInit(self):
vertex_shader = shaders.compileShader(
"""
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
""",
GL_VERTEX_SHADER)
fragment_shader = shaders.compileShader(
"""
void main()
{
gl_FragColor = vec4(0, 1, 0, 1);
}
""",
GL_FRAGMENT_SHADER)
self.shader = shaders.compileProgram(vertex_shader, fragment_shader)
self.vbo = vbo.VBO(
array([
[0, 1, 0],
[-1, -1, 0],
[1, -1, 0],
[2, -1, 0],
[4, -1, 0],
[4, 1, 0],
[2, -1, 0],
[4, 1, 0],
[2, 1, 0]
], "f"))
def Render(self, mode):
"""Render the geometry for the scene."""
shaders.glUseProgram(self.shader)
try:
self.vbo.bind()
try:
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointerf(self.vbo)
glDrawArrays(GL_TRIANGLES, 0, 9)
finally:
self.vbo.unbind()
glDisableClientState(GL_VERTEX_ARRAY)
finally:
shaders.glUseProgram(0)
if __name__ == "__main__":
TestContext.ContextMainLoop()