root / PyOpenGL-Demo / redbook / hello.py @ 2
Historique | Voir | Annoter | Télécharger (3,43 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 |
Converted to Python 6/00 by Jason Petrone
|
| 9 |
|
| 10 |
/*
|
| 11 |
* Copyright (c) 1993-1997, Silicon Graphics, Inc.
|
| 12 |
* ALL RIGHTS RESERVED
|
| 13 |
* Permission to use, copy, modify, and distribute this software for
|
| 14 |
* any purpose and without fee is hereby granted, provided that the above
|
| 15 |
* copyright notice appear in all copies and that both the copyright notice
|
| 16 |
* and this permission notice appear in supporting documentation, and that
|
| 17 |
* the name of Silicon Graphics, Inc. not be used in advertising
|
| 18 |
* or publicity pertaining to distribution of the software without specific,
|
| 19 |
* written prior permission.
|
| 20 |
*
|
| 21 |
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
| 22 |
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
| 23 |
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
|
| 24 |
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
| 25 |
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
|
| 26 |
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
|
| 27 |
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
|
| 28 |
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
|
| 29 |
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
|
| 30 |
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
| 31 |
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
| 32 |
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 33 |
*
|
| 34 |
* US Government Users Restricted Rights
|
| 35 |
* Use, duplication, or disclosure by the Government is subject to
|
| 36 |
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
| 37 |
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
| 38 |
* clause at DFARS 252.227-7013 and/or in similar or successor
|
| 39 |
* clauses in the FAR or the DOD or NASA FAR Supplement.
|
| 40 |
* Unpublished-- rights reserved under the copyright laws of the
|
| 41 |
* United States. Contractor/manufacturer is Silicon Graphics,
|
| 42 |
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
|
| 43 |
*
|
| 44 |
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
|
| 45 |
*/
|
| 46 |
'''
|
| 47 |
|
| 48 |
# hello.c
|
| 49 |
# This is a simple, introductory OpenGL program.
|
| 50 |
|
| 51 |
import sys |
| 52 |
|
| 53 |
try:
|
| 54 |
from OpenGL.GLUT import * |
| 55 |
from OpenGL.GL import * |
| 56 |
from OpenGL.GLU import * |
| 57 |
except:
|
| 58 |
print ''' |
| 59 |
ERROR: PyOpenGL not installed properly.
|
| 60 |
'''
|
| 61 |
sys.exit() |
| 62 |
|
| 63 |
|
| 64 |
def display(): |
| 65 |
# clear all pixels
|
| 66 |
glClear (GL_COLOR_BUFFER_BIT) |
| 67 |
|
| 68 |
# draw white polygon (rectangle) with corners at
|
| 69 |
# (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
|
| 70 |
glColor3f (1.0, 1.0, 1.0) |
| 71 |
glBegin(GL_POLYGON) |
| 72 |
glVertex3f (0.25, 0.25, 0.0) |
| 73 |
glVertex3f (0.75, 0.25, 0.0) |
| 74 |
glVertex3f (0.75, 0.75, 0.0) |
| 75 |
glVertex3f (0.25, 0.75, 0.0) |
| 76 |
glEnd() |
| 77 |
|
| 78 |
# don't wait!
|
| 79 |
# start processing buffered OpenGL routines
|
| 80 |
glFlush (); |
| 81 |
|
| 82 |
def init(): |
| 83 |
# select clearing color
|
| 84 |
glClearColor (0.0, 0.0, 0.0, 0.0) |
| 85 |
|
| 86 |
# initialize viewing values
|
| 87 |
glMatrixMode(GL_PROJECTION) |
| 88 |
glLoadIdentity() |
| 89 |
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) |
| 90 |
|
| 91 |
# Declare initial window size, position, and display mode
|
| 92 |
# (single buffer and RGBA). Open window with "hello"
|
| 93 |
# in its title bar. Call initialization routines.
|
| 94 |
# Register callback function to display graphics.
|
| 95 |
# Enter main loop and process events.
|
| 96 |
|
| 97 |
glutInit(sys.argv) |
| 98 |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) |
| 99 |
glutInitWindowSize(250, 250) |
| 100 |
glutInitWindowPosition(100, 100) |
| 101 |
glutCreateWindow("hello")
|
| 102 |
init() |
| 103 |
glutDisplayFunc(display) |
| 104 |
glutMainLoop() |