-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (51 loc) · 1.75 KB
/
main.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
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
import sys
class Graphics(object):
def __init__(self, name="graphics", window_size=(500, 500)):
self.name = name
self.window_size = window_size
self.initGL()
def initGL(self):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(*self.window_size)
glutInitWindowPosition(0, 0)
glutCreateWindow(self.name)
glClearColor(0.,0.,0.,1.)
glShadeModel(GL_SMOOTH)
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
lightZeroPosition = [10., 4., 10., 1.]
lightZeroColor = [0.8, 1.0, 0.8, 1.0] #green tinged
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
glEnable(GL_LIGHT0)
glutDisplayFunc(self.display)
glutIdleFunc(self.display)
glMatrixMode(GL_PROJECTION)
gluPerspective(40., 1., 1., 40.)
glMatrixMode(GL_MODELVIEW)
gluLookAt(0, 0, 10,
0, 0, 0,
0, 1, 0)
glPushMatrix()
glutMainLoop()
def display(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glPushMatrix()
color = [1.0, 0., 0., 1.]
glMaterialfv(GL_FRONT,GL_DIFFUSE,color)
# glTranslate(2, 0, 0)
# glutSolidSphere(2, 20, 20)
glTranslate(2, 0, 0)
glutSolidCube(3)
glPopMatrix()
glutSwapBuffers()
def drawRectangles(self, rectangles):
if __name__ == '__main__':
g = Graphics()