Statistics
| Revision:

root / PyOpenGL-Demo / GLE / maintest.py @ 1

History | View | Annotate | Download (1.6 kB)

1
#!/usr/bin/python
2

    
3
# This is statement is required by the build system to query build info
4
if __name__ == '__build__':
5
        raise Exception
6

    
7

    
8
import sys
9
from OpenGL.GL import *
10
from OpenGL.GLE import *
11
from OpenGL.GLUT import *
12

    
13

    
14
lastx=0
15
lasty=0
16

    
17
# get notified of mouse motions
18
def MouseMotion (x, y):
19
        global lastx, lasty
20
        lastx = x
21
        lasty = y
22
        glutPostRedisplay ()
23

    
24

    
25
def JoinStyle (msg):
26
        sys.exit(0)
27

    
28

    
29
# set up a light 
30
lightOnePosition = (40.0, 40, 100.0, 0.0)
31
lightOneColor = (0.99, 0.99, 0.99, 1.0) 
32

    
33
lightTwoPosition = (-40.0, 40, 100.0, 0.0)
34
lightTwoColor = (0.99, 0.99, 0.99, 1.0) 
35

    
36

    
37
def main(DrawStuff):
38
        global glutDisplayFunc, glutMotionFunc
39
        # initialize glut 
40
        glutInit(sys.argv)
41
        glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
42
        glutCreateWindow("basic demo")
43
        glutDisplayFunc(DrawStuff)
44
        glutMotionFunc(MouseMotion)
45

    
46
        # create popup menu */
47
        glutCreateMenu (JoinStyle)
48
        glutAddMenuEntry ("Exit", 99)
49
        glutAttachMenu (GLUT_RIGHT_BUTTON)
50

    
51
        # initialize GL */
52
        glClearDepth (1.0)
53
        glEnable (GL_DEPTH_TEST)
54
        glClearColor (0.0, 0.0, 0.0, 0.0)
55
        glShadeModel (GL_SMOOTH)
56

    
57
        glMatrixMode (GL_PROJECTION)
58
        # roughly, measured in centimeters */
59
        glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0)
60
        glMatrixMode(GL_MODELVIEW)
61

    
62
        # initialize lighting */
63
        glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition)
64
        glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor)
65
        glEnable (GL_LIGHT0)
66
        glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition)
67
        glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor)
68
        glEnable (GL_LIGHT1)
69
        glEnable (GL_LIGHTING)
70
        glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE)
71
        glEnable (GL_COLOR_MATERIAL)
72

    
73
        glutMainLoop ()