-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyopengl_1.py
86 lines (75 loc) · 1.41 KB
/
pyopengl_1.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
80
81
82
83
import pygame, sys
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1)
)
edges = (
(0, 1),
(0, 3),
(0, 4),
(2, 1),
(2, 3),
(2, 7),
(6, 3),
(6, 4),
(6, 7),
(5, 1),
(5, 4),
(5, 7),
)
surfaces = (
(0, 1, 2, 3),
(3, 2, 7, 6),
(6, 7, 5, 4),
(4, 5, 1, 0),
(1, 5, 7, 2),
(4, 0, 3, 6),
)
def draw_cube():
glBegin(GL_QUADS)
for surface in surfaces:
for vertex in surface:
glColor3fv((0, 1, 1))
glVertex3fv(vertices[vertex])
glEnd()
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glColor3fv((1, 0, 0))
glVertex3fv(vertices[vertex])
glEnd()
def main():
pygame.init()
displayDim = (800, 600)
pygame.display.set_mode(displayDim, DOUBLEBUF | OPENGL)
gluPerspective(45.0, (displayDim[0] / displayDim[1]), 1, 50.0)
# moving back
glTranslatef(0.0, 0.0, -5.0)
# where we might be
glRotatef(40, 20, 20, 0)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
#print event, event.button
if event.button == 4:
glTranslatef(0.0, 0.0, 1.0)
elif event.button == 5:
glTranslatef(0.0, 0.0, -1.0)
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
draw_cube()
pygame.display.flip()
pygame.time.wait(10)
main()