Statistiques
| Révision :

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

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

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

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

    
44
'''
45
/*
46
 *  drawf.c
47
 *  Draws the bitmapped letter F on the screen(several times).
48
 *  This demonstrates use of the glBitmap() call.
49
 */
50
'''
51

    
52
import sys, struct
53

    
54
try:
55
        from OpenGL.GLUT import *
56
        from OpenGL.GL import *
57
except:
58
        print('''
59
ERROR: PyOpenGL not installed properly.  
60
''')
61
        sys.exit()
62

    
63

    
64
rasterBytes = (
65
        0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
66
        0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
67
        0xff, 0xc0, 0xff, 0xc0)
68

    
69
rasters = b''
70
for byte in rasterBytes:
71
        rasters = rasters + struct.pack('B', byte)
72

    
73
def init():
74
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
75
        glClearColor(0.0, 0.0, 0.0, 0.0)
76

    
77
def display():
78
        print('display')
79
        glClear(GL_COLOR_BUFFER_BIT)
80
        glColor3f(1.0, 1.0, 1.0)
81
        glRasterPos2i(20, 20)
82
        print('beginning bitmaps')
83
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
84
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
85
        glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters)
86
        print('flushing')
87
        glFlush()
88
        
89
def reshape(w, h):
90
        print('reshape')
91
        glViewport(0, 0, w, h)
92
        glMatrixMode(GL_PROJECTION)
93
        glLoadIdentity()
94
        glOrtho(0, w, 0, h, -1.0, 1.0)
95
        glMatrixMode(GL_MODELVIEW)
96

    
97
def keyboard(key, x, y):
98
        print('keyboard', key, x,y)
99
        if key == str.encode(chr(27)):
100
                sys.exit()
101

    
102
#  Main Loop
103
#  Open window with initial window size, title bar, 
104
#  RGBA display mode, and handle input events.
105
if __name__ == "__main__":
106
        glutInit(sys.argv)
107
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
108
        glutInitWindowSize(100, 100)
109
        glutInitWindowPosition(100, 100)
110
        glutCreateWindow(b'drawf')
111
        init()
112
        glutReshapeFunc(reshape)
113
        glutKeyboardFunc(keyboard)
114
        glutDisplayFunc(display)
115
        
116
        glutMainLoop()