Statistics
| Revision:

root / PyOpenGL-Demo / redbook / double.py @ 11

History | View | Annotate | Download (3.7 kB)

1 11 equemene
#!/usr/bin/env python3
2 1 equemene
3 1 equemene
# This is statement is required by the build system to query build info
4 1 equemene
if __name__ == '__build__':
5 11 equemene
        raise(Exception)
6 1 equemene
7 1 equemene
'''
8 1 equemene
double.c from the Redbook examples.
9 1 equemene
Converted to Python by Jason L. Petrone 6/00
10 1 equemene

11 1 equemene
/*
12 1 equemene
 * Copyright(c) 1993-1997, Silicon Graphics, Inc.
13 1 equemene
 * ALL RIGHTS RESERVED
14 1 equemene
 * Permission to use, copy, modify, and distribute this software for
15 1 equemene
 * any purpose and without fee is hereby granted, provided that the above
16 1 equemene
 * copyright notice appear in all copies and that both the copyright notice
17 1 equemene
 * and this permission notice appear in supporting documentation, and that
18 1 equemene
 * the name of Silicon Graphics, Inc. not be used in advertising
19 1 equemene
 * or publicity pertaining to distribution of the software without specific,
20 1 equemene
 * written prior permission.
21 1 equemene
 *
22 1 equemene
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
23 1 equemene
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
24 1 equemene
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
25 1 equemene
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
26 1 equemene
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
27 1 equemene
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
28 1 equemene
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
29 1 equemene
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
30 1 equemene
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
31 1 equemene
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
32 1 equemene
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
33 1 equemene
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
34 1 equemene
 *
35 1 equemene
 * US Government Users Restricted Rights
36 1 equemene
 * Use, duplication, or disclosure by the Government is subject to
37 1 equemene
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
38 1 equemene
 *(c)(1)(ii) of the Rights in Technical Data and Computer Software
39 1 equemene
 * clause at DFARS 252.227-7013 and/or in similar or successor
40 1 equemene
 * clauses in the FAR or the DOD or NASA FAR Supplement.
41 1 equemene
 * Unpublished-- rights reserved under the copyright laws of the
42 1 equemene
 * United States.  Contractor/manufacturer is Silicon Graphics,
43 1 equemene
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
44 1 equemene
 *
45 1 equemene
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
46 1 equemene
 */
47 1 equemene
'''
48 1 equemene
49 1 equemene
'''
50 1 equemene
/*
51 1 equemene
 *  double.c
52 1 equemene
 *  This is a simple double buffered program.
53 1 equemene
 *  Pressing the left mouse button rotates the rectangle.
54 1 equemene
 *  Pressing the middle mouse button stops the rotation.
55 1 equemene
 */
56 1 equemene
 '''
57 1 equemene
58 1 equemene
import sys
59 1 equemene
60 1 equemene
try:
61 1 equemene
  from OpenGL.GLUT import *
62 1 equemene
  from OpenGL.GL import *
63 1 equemene
  from OpenGL.GLU import *
64 1 equemene
except:
65 11 equemene
  print('''
66 1 equemene
ERROR: PyOpenGL not installed properly.
67 11 equemene
        ''')
68 1 equemene
  sys.exit()
69 1 equemene
70 1 equemene
71 1 equemene
spin = 0.0
72 1 equemene
73 1 equemene
def display():
74 1 equemene
   glClear(GL_COLOR_BUFFER_BIT)
75 1 equemene
   glPushMatrix()
76 1 equemene
   glRotatef(spin, 0.0, 0.0, 1.0)
77 1 equemene
   glColor3f(1.0, 1.0, 1.0)
78 1 equemene
   glRectf(-25.0, -25.0, 25.0, 25.0)
79 1 equemene
   glPopMatrix()
80 1 equemene
   glutSwapBuffers()
81 1 equemene
82 1 equemene
def spinDisplay():
83 1 equemene
   global spin
84 1 equemene
   spin = spin + 2.0
85 1 equemene
   if(spin > 360.0):
86 1 equemene
      spin = spin - 360.0
87 1 equemene
   glutPostRedisplay()
88 1 equemene
89 1 equemene
def init():
90 1 equemene
   glClearColor(0.0, 0.0, 0.0, 0.0)
91 1 equemene
   glShadeModel(GL_FLAT)
92 1 equemene
93 1 equemene
def reshape(w, h):
94 1 equemene
   glViewport(0, 0, w, h)
95 1 equemene
   glMatrixMode(GL_PROJECTION)
96 1 equemene
   glLoadIdentity()
97 1 equemene
   glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0)
98 1 equemene
   glMatrixMode(GL_MODELVIEW)
99 1 equemene
   glLoadIdentity()
100 1 equemene
101 1 equemene
def mouse(button, state, x, y):
102 1 equemene
   if button == GLUT_LEFT_BUTTON:
103 1 equemene
       if(state == GLUT_DOWN):
104 1 equemene
          glutIdleFunc(spinDisplay)
105 1 equemene
   elif button == GLUT_MIDDLE_BUTTON or button == GLUT_RIGHT_BUTTON:
106 1 equemene
       if(state == GLUT_DOWN):
107 1 equemene
           glutIdleFunc(None)
108 1 equemene
109 1 equemene
110 1 equemene
#  Request double buffer display mode.
111 1 equemene
#  Register mouse input callback functions
112 1 equemene
glutInit(sys.argv)
113 1 equemene
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
114 1 equemene
glutInitWindowSize(250, 250)
115 1 equemene
glutInitWindowPosition(100, 100)
116 11 equemene
glutCreateWindow(b'Double')
117 1 equemene
init()
118 1 equemene
glutDisplayFunc(display)
119 1 equemene
glutReshapeFunc(reshape)
120 1 equemene
glutMouseFunc(mouse)
121 1 equemene
glutMainLoop()