Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (3,7 ko)

1
#!/usr/bin/env python3
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
double.c from the Redbook examples.  
9
Converted to Python by Jason L. Petrone 6/00
10

11
/*
12
 * Copyright(c) 1993-1997, Silicon Graphics, Inc.
13
 * ALL RIGHTS RESERVED 
14
 * Permission to use, copy, modify, and distribute this software for 
15
 * any purpose and without fee is hereby granted, provided that the above
16
 * copyright notice appear in all copies and that both the copyright notice
17
 * and this permission notice appear in supporting documentation, and that 
18
 * the name of Silicon Graphics, Inc. not be used in advertising
19
 * or publicity pertaining to distribution of the software without specific,
20
 * written prior permission. 
21
 *
22
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
23
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
24
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
25
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
26
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
27
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
28
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
29
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
30
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
31
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
32
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
33
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
34
 * 
35
 * US Government Users Restricted Rights 
36
 * Use, duplication, or disclosure by the Government is subject to
37
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
38
 *(c)(1)(ii) of the Rights in Technical Data and Computer Software
39
 * clause at DFARS 252.227-7013 and/or in similar or successor
40
 * clauses in the FAR or the DOD or NASA FAR Supplement.
41
 * Unpublished-- rights reserved under the copyright laws of the
42
 * United States.  Contractor/manufacturer is Silicon Graphics,
43
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
44
 *
45
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
46
 */
47
'''
48

    
49
'''
50
/*
51
 *  double.c
52
 *  This is a simple double buffered program.
53
 *  Pressing the left mouse button rotates the rectangle.
54
 *  Pressing the middle mouse button stops the rotation.
55
 */
56
 '''
57

    
58
import sys
59

    
60
try:
61
  from OpenGL.GLUT import *
62
  from OpenGL.GL import *
63
  from OpenGL.GLU import *
64
except:
65
  print('''
66
ERROR: PyOpenGL not installed properly.  
67
        ''')
68
  sys.exit()
69

    
70

    
71
spin = 0.0
72

    
73
def display():
74
   glClear(GL_COLOR_BUFFER_BIT)
75
   glPushMatrix()
76
   glRotatef(spin, 0.0, 0.0, 1.0)
77
   glColor3f(1.0, 1.0, 1.0)
78
   glRectf(-25.0, -25.0, 25.0, 25.0)
79
   glPopMatrix()
80
   glutSwapBuffers()
81

    
82
def spinDisplay():
83
   global spin
84
   spin = spin + 2.0
85
   if(spin > 360.0):
86
      spin = spin - 360.0
87
   glutPostRedisplay()
88

    
89
def init():
90
   glClearColor(0.0, 0.0, 0.0, 0.0)
91
   glShadeModel(GL_FLAT)
92

    
93
def reshape(w, h):
94
   glViewport(0, 0, w, h)
95
   glMatrixMode(GL_PROJECTION)
96
   glLoadIdentity()
97
   glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0)
98
   glMatrixMode(GL_MODELVIEW)
99
   glLoadIdentity()
100

    
101
def mouse(button, state, x, y):
102
   if button == GLUT_LEFT_BUTTON:
103
       if(state == GLUT_DOWN):
104
          glutIdleFunc(spinDisplay)
105
   elif button == GLUT_MIDDLE_BUTTON or button == GLUT_RIGHT_BUTTON:
106
       if(state == GLUT_DOWN):
107
           glutIdleFunc(None)
108
   
109

    
110
#  Request double buffer display mode.
111
#  Register mouse input callback functions
112
glutInit(sys.argv)
113
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
114
glutInitWindowSize(250, 250)
115
glutInitWindowPosition(100, 100)
116
glutCreateWindow(b'Double')
117
init()
118
glutDisplayFunc(display)
119
glutReshapeFunc(reshape)
120
glutMouseFunc(mouse)
121
glutMainLoop()
122