-
Notifications
You must be signed in to change notification settings - Fork 1
/
glut_example3dnormals.py
57 lines (47 loc) · 1.23 KB
/
glut_example3dnormals.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
#Based on https://github.com/Habitats/uni/blob/master/img_processing/project/graphics_modern2.py
from __future__ import print_function
from OpenGL.GLUT import *
from OpenGL.GLUT.freeglut import *
import common3dnormals, time
import OpenGL.GL as gl
lastDrawTime = 0.
aspect = 1.
params = None
width, height = None, None
def draw():
common3dnormals.draw(params, aspect)
glutSwapBuffers()
def main():
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(640, 480)
window = glutCreateWindow("Hello world!")
glutReshapeFunc(reshape)
glutDisplayFunc(draw)
glutIdleFunc(idle)
glutKeyboardFunc(keyPressed) # Checks for key strokes
global params
params = common3dnormals.init()
glutMainLoop()
def reshape(widthIn, heightIn):
global width, height
width = widthIn
height = heightIn
global aspect
aspect = (width / float(height))
gl.glViewport(0, 0, width, height)
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glDisable(gl.GL_CULL_FACE)
gl.glClearColor(0.8, 0.8, 0.8, 1.0)
glutPostRedisplay()
def idle():
global lastDrawTime
now = time.time()
elapse = now - lastDrawTime
if elapse > 0.05:
glutPostRedisplay()
lastDrawTime = now
def keyPressed(*args):
sys.exit()
if __name__=="__main__":
glutInit(sys.argv)
main()