Statistics
| Revision:

root / PyOpenGL-Demo / redbook / hello.py @ 1

History | View | Annotate | Download (3.4 kB)

1 1 equemene
#!/usr/bin/python
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 1 equemene
        raise Exception
6 1 equemene
7 1 equemene
'''
8 1 equemene
Converted to Python 6/00 by Jason Petrone
9 1 equemene

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