root / PyOpenGL-Demo / redbook / cube.py @ 2
Historique | Voir | Annoter | Télécharger (3,34 ko)
| 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 |
|
| 9 |
cube.py
|
| 10 |
Converted to Python by Jason Petrone 6/00
|
| 11 |
|
| 12 |
/*
|
| 13 |
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
| 14 |
* ALL RIGHTS RESERVED
|
| 15 |
* Permission to use, copy, modify, and distribute this software for
|
| 16 |
* any purpose and without fee is hereby granted, provided that the above
|
| 17 |
* copyright notice appear in all copies and that both the copyright notice
|
| 18 |
* and this permission notice appear in supporting documentation, and that
|
| 19 |
* the name of Silicon Graphics, Inc. not be used in advertising
|
| 20 |
* or publicity pertaining to distribution of the software without specific,
|
| 21 |
* written prior permission.
|
| 22 |
*
|
| 23 |
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
| 24 |
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
| 25 |
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
| 26 |
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
| 27 |
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
| 28 |
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
| 29 |
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
| 30 |
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
| 31 |
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
| 32 |
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
| 33 |
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
| 34 |
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 35 |
*
|
| 36 |
* US Government Users Restricted Rights
|
| 37 |
* Use, duplication, or disclosure by the Government is subject to
|
| 38 |
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
| 39 |
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
| 40 |
* clause at DFARS 252.227-7013 and/or in similar or successor
|
| 41 |
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
| 42 |
* Unpublished-- rights reserved under the copyright laws of the
|
| 43 |
* United States. Contractor/manufacturer is Silicon Graphics,
|
| 44 |
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
| 45 |
*
|
| 46 |
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
| 47 |
*/
|
| 48 |
|
| 49 |
'''
|
| 50 |
|
| 51 |
# cube.c
|
| 52 |
# This program demonstrates a single modeling transformation,
|
| 53 |
# glScalef() and a single viewing transformation, gluLookAt().
|
| 54 |
# A wireframe cube is rendered.
|
| 55 |
|
| 56 |
import sys |
| 57 |
|
| 58 |
try:
|
| 59 |
from OpenGL.GLUT import * |
| 60 |
from OpenGL.GL import * |
| 61 |
from OpenGL.GLU import * |
| 62 |
except:
|
| 63 |
print ''' |
| 64 |
ERROR: PyOpenGL not installed properly.
|
| 65 |
'''
|
| 66 |
|
| 67 |
def init(): |
| 68 |
glClearColor (0.0, 0.0, 0.0, 0.0) |
| 69 |
glShadeModel (GL_FLAT) |
| 70 |
|
| 71 |
def display(): |
| 72 |
glClear (GL_COLOR_BUFFER_BIT) |
| 73 |
glColor3f (1.0, 1.0, 1.0) |
| 74 |
glLoadIdentity () # clear the matrix
|
| 75 |
# viewing transformation
|
| 76 |
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) |
| 77 |
glScalef (1.0, 2.0, 1.0) # modeling transformation |
| 78 |
glutWireCube (1.0)
|
| 79 |
glFlush () |
| 80 |
|
| 81 |
def reshape (w, h): |
| 82 |
glViewport (0, 0, w, h) |
| 83 |
glMatrixMode (GL_PROJECTION) |
| 84 |
glLoadIdentity () |
| 85 |
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0) |
| 86 |
glMatrixMode (GL_MODELVIEW) |
| 87 |
|
| 88 |
def keyboard(key, x, y): |
| 89 |
if key == chr(27): |
| 90 |
import sys |
| 91 |
sys.exit(0)
|
| 92 |
|
| 93 |
glutInit(sys.argv) |
| 94 |
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) |
| 95 |
glutInitWindowSize (500, 500) |
| 96 |
glutInitWindowPosition (100, 100) |
| 97 |
glutCreateWindow ('cube')
|
| 98 |
init () |
| 99 |
glutDisplayFunc(display) |
| 100 |
glutReshapeFunc(reshape) |
| 101 |
glutKeyboardFunc(keyboard) |
| 102 |
glutMainLoop() |