-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.py
68 lines (52 loc) · 1.27 KB
/
7.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
import glfw
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
def render():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glLoadIdentity()
drawFrame()
glColor3ub(255, 255, 255)
drawTriangle()
glRotatef(30, 0, 0, 1)
glTranslatef(0.6, 0, 0)
drawFrame()
glColor3ub(255, 0, 0)
drawTriangle()
glLoadIdentity()
glTranslatef(0.6, 0, 0)
glRotatef(30, 0, 0, 1)
drawFrame()
glColor3ub(0, 0, 255)
drawTriangle()
def drawFrame():
glBegin(GL_LINES)
glColor3ub(255, 0, 0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([1.,0.]))
glColor3ub(0, 255, 0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([0.,1.]))
glEnd()
def drawTriangle():
glBegin(GL_TRIANGLES)
glVertex2fv(np.array([0.,.5]))
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([.5,0.]))
glEnd()
def main():
if not glfw.init():
return
window = glfw.create_window(480,480,'A', None,None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
while not glfw.window_should_close(window):
glfw.poll_events()
render()
glfw.swap_buffers(window)
glfw.terminate()
if __name__ == "__main__":
main()