Debian Codegraph @

examples/IPython Kernel/gui/gui-glut.py

raw
1 #!/usr/bin/env python
2 """Simple GLUT example to manually test event loop integration.
3
4 This is meant to run tests manually in ipython as:
5
6 In [5]: %gui glut
7
8 In [6]: %run gui-glut.py
9
10 In [7]: gl.glClearColor(1,1,1,1)
11 """
12
13 #!/usr/bin/env python
14 import sys
15 import OpenGL.GL as gl
16 import OpenGL.GLUT as glut
17
18 def close():
19 glut.glutDestroyWindow(glut.glutGetWindow())
20
21 def display():
22 gl.glClear (gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
23 glut.glutSwapBuffers()
24
25 def resize(width,height):
26 gl.glViewport(0, 0, width, height+4)
27 gl.glMatrixMode(gl.GL_PROJECTION)
28 gl.glLoadIdentity()
29 gl.glOrtho(0, width, 0, height+4, -1, 1)
30 gl.glMatrixMode(gl.GL_MODELVIEW)
31
32 if glut.glutGetWindow() > 0:
33 interactive = True
34 glut.glutInit(sys.argv)
35 glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
36 glut.GLUT_RGBA |
37 glut.GLUT_DEPTH)
38 else:
39 interactive = False
40
41 glut.glutCreateWindow(b'gui-glut')
42 glut.glutDisplayFunc(display)
43 glut.glutReshapeFunc(resize)
44 # This is necessary on osx to be able to close the window
45 # (else the close button is disabled)
46 if sys.platform == 'darwin' and not bool(glut.HAVE_FREEGLUT):
47 glut.glutWMCloseFunc(close)
48 gl.glClearColor(0,0,0,1)
49
50 if not interactive:
51 glut.glutMainLoop()