Statistics
| Revision:

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

History | View | Annotate | Download (3.6 kB)

1 1 equemene
#!/usr/bin/python
2 1 equemene
'''
3 1 equemene
drawf.c from the Redbook examples.
4 1 equemene
Converted to Python by Jason L. Petrone 7/00
5 1 equemene

6 1 equemene
/*
7 1 equemene
 * Copyright(c) 1993-1997, Silicon Graphics, Inc.
8 1 equemene
 * ALL RIGHTS RESERVED
9 1 equemene
 * Permission to use, copy, modify, and distribute this software for
10 1 equemene
 * any purpose and without fee is hereby granted, provided that the above
11 1 equemene
 * copyright notice appear in all copies and that both the copyright notice
12 1 equemene
 * and this permission notice appear in supporting documentation, and that
13 1 equemene
 * the name of Silicon Graphics, Inc. not be used in advertising
14 1 equemene
 * or publicity pertaining to distribution of the software without specific,
15 1 equemene
 * written prior permission.
16 1 equemene
 *
17 1 equemene
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
18 1 equemene
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
19 1 equemene
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
20 1 equemene
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
21 1 equemene
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
22 1 equemene
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
23 1 equemene
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
24 1 equemene
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
25 1 equemene
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
26 1 equemene
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
27 1 equemene
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
28 1 equemene
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
29 1 equemene
 *
30 1 equemene
 * US Government Users Restricted Rights
31 1 equemene
 * Use, duplication, or disclosure by the Government is subject to
32 1 equemene
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
33 1 equemene
 *(c)(1)(ii) of the Rights in Technical Data and Computer Software
34 1 equemene
 * clause at DFARS 252.227-7013 and/or in similar or successor
35 1 equemene
 * clauses in the FAR or the DOD or NASA FAR Supplement.
36 1 equemene
 * Unpublished-- rights reserved under the copyright laws of the
37 1 equemene
 * United States.  Contractor/manufacturer is Silicon Graphics,
38 1 equemene
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
39 1 equemene
 *
40 1 equemene
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
41 1 equemene
 */
42 1 equemene
'''
43 1 equemene
44 1 equemene
'''
45 1 equemene
/*
46 1 equemene
 *  drawf.c
47 1 equemene
 *  Draws the bitmapped letter F on the screen(several times).
48 1 equemene
 *  This demonstrates use of the glBitmap() call.
49 1 equemene
 */
50 1 equemene
'''
51 1 equemene
52 1 equemene
import sys, struct
53 1 equemene
54 1 equemene
try:
55 1 equemene
        from OpenGL.GLUT import *
56 1 equemene
        from OpenGL.GL 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
rasterBytes = (
65 1 equemene
        0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
66 1 equemene
        0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
67 1 equemene
        0xff, 0xc0, 0xff, 0xc0)
68 1 equemene
69 1 equemene
rasters = ''
70 1 equemene
for byte in rasterBytes:
71 1 equemene
        rasters = rasters + struct.pack('B', byte)
72 1 equemene
73 1 equemene
def init():
74 1 equemene
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
75 1 equemene
        glClearColor(0.0, 0.0, 0.0, 0.0)
76 1 equemene
77 1 equemene
def display():
78 1 equemene
        print 'display'
79 1 equemene
        glClear(GL_COLOR_BUFFER_BIT)
80 1 equemene
        glColor3f(1.0, 1.0, 1.0)
81 1 equemene
        glRasterPos2i(20, 20)
82 1 equemene
        print 'beginning bitmaps'
83 1 equemene
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
84 1 equemene
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
85 1 equemene
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
86 1 equemene
        print 'flushing'
87 1 equemene
        glFlush()
88 1 equemene
89 1 equemene
def reshape(w, h):
90 1 equemene
        print 'reshape'
91 1 equemene
        glViewport(0, 0, w, h)
92 1 equemene
        glMatrixMode(GL_PROJECTION)
93 1 equemene
        glLoadIdentity()
94 1 equemene
        glOrtho(0, w, 0, h, -1.0, 1.0)
95 1 equemene
        glMatrixMode(GL_MODELVIEW)
96 1 equemene
97 1 equemene
def keyboard(key, x, y):
98 1 equemene
        print 'keyboard', key, x,y
99 1 equemene
        if key == chr(27):
100 1 equemene
                sys.exit()
101 1 equemene
102 1 equemene
#  Main Loop
103 1 equemene
#  Open window with initial window size, title bar,
104 1 equemene
#  RGBA display mode, and handle input events.
105 1 equemene
if __name__ == "__main__":
106 1 equemene
        glutInit(sys.argv)
107 1 equemene
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
108 1 equemene
        glutInitWindowSize(100, 100)
109 1 equemene
        glutInitWindowPosition(100, 100)
110 1 equemene
        glutCreateWindow('drawf')
111 1 equemene
        init()
112 1 equemene
        glutReshapeFunc(reshape)
113 1 equemene
        glutKeyboardFunc(keyboard)
114 1 equemene
        glutDisplayFunc(display)
115 1 equemene
116 1 equemene
        glutMainLoop()