-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopengl1.py
46 lines (34 loc) · 1.1 KB
/
opengl1.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
import glfw
from OpenGL.GL import *
import numpy as np
import math
if not glfw.init():
raise Exception('AAAAAA')
window = glfw.create_window(1024, 768, 'XXXXXDDDD', None, None)
if not window:
glfw.terminate()
raise Exception('AAAAA')
glfw.set_window_pos(window, 100, 100)
glfw.make_context_current(window)
glClearColor(0, 0, 0, 0)
vertices = np.array([-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0], dtype=np.float32)
colors = np.array([1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0], dtype=np.float32)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(3, GL_FLOAT, 0, vertices)
glEnableClientState(GL_COLOR_ARRAY)
glColorPointer(3, GL_FLOAT, 0, colors)
while not glfw.window_should_close(window):
glfw.poll_events()
glClear(GL_COLOR_BUFFER_BIT)
ct = glfw.get_time()
glLoadIdentity()
glScale(abs(math.sin(ct)), abs(math.cos(ct)), 1)
glRotatef(ct, 0, ct / 2.0, 0)
glTranslatef(math.sin(ct), math.cos(ct), 1)
glDrawArrays(GL_TRIANGLES, 0, 3)
glfw.swap_buffers(window)
glfw.terminate()