-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-2-3.py
79 lines (61 loc) · 2.26 KB
/
test-2-3.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# import standard library
import sys
# import third party library
from OpenGL.GL import *
# import local library
from core.base import Base, baseApp
from core.openGLUtils import OpenGLUtils
from core.attribute import Attribute
# render six points in a hexagon arrangement
class Test(Base):
def __init__(self, screenSize=[512, 512], title=""):
super().__init__(screenSize, title)
def initializeGL(self):
super().initializeGL()
### initialize program ###
vsCode = """
in vec3 position;
void main()
{
gl_Position = vec4(position.x,
position.y, position.z, 1.0);
}
"""
fsCode = """
out vec4 fragColor;
void main()
{
fragColor = vec4(1.0, 1.0, 0.0, 1.0);
}
"""
# send code to GPU and compile; store program reference
self.programRef = OpenGLUtils.initializeProgram(vsCode, fsCode)
### render settings (optional) ###
glLineWidth(4)
### set up vertex array object ###
self.vaoRef = glGenVertexArrays(1)
glBindVertexArray(self.vaoRef)
### set up vertex attribute ###
self.positionData = [[0.8, 0.0, 0.0], [0.4, 0.6, 0.0],
[-0.4, 0.6, 0.0], [-0.8, 0.0, 0.0],
[-0.4, -0.6, 0.0], [0.4, -0.6, 0.0]]
self.vertexCount = len(self.positionData)
self.positionAttribute = Attribute("vec3", self.positionData)
self.positionAttribute.associateVariable(self.programRef, "position")
def paintGL(self):
super().paintGL()
# select program to use when rendering
glUseProgram(self.programRef)
# renders geometric objects using selected program
glDrawArrays(GL_LINE_LOOP, 0, self.vertexCount)
#glDrawArrays(GL_LINES, 0, self.vertexCount)
#glDrawArrays(GL_LINE_STRIP, 0, self.vertexCount)
#glDrawArrays(GL_TRIANGLES, 0, self.vertexCount)
#glDrawArrays(GL_TRIANGLE_FAN, 0, self.vertexCount)
def main():
app = baseApp(sys.argv)
window = Test(title="Test-2-3")
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()