Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (3,38 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
smooth.c from the Redbook examples.  
9
Converted to Python by Jason L. Petrone 7/00
10

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

    
49
'''
50
/*
51
 * smooth.c
52
 * This program demonstrates smooth shading.
53
 * A smooth shaded polygon is drawn in a 2-D projection.
54
 */
55
'''
56

    
57
import sys, struct
58

    
59
try:
60
  from OpenGL.GLUT import *
61
  from OpenGL.GL import *
62
  from OpenGL.GLU import *
63
except:
64
  print('''
65
ERROR: PyOpenGL not installed properly.  
66
        ''')
67
  sys.exit()
68

    
69

    
70
def init():
71
   glClearColor(0.0, 0.0, 0.0, 0.0)
72
   glShadeModel(GL_SMOOTH)
73

    
74
def triangle():
75
   glBegin(GL_TRIANGLES)
76
   glColor3f(1.0, 0.0, 0.0)
77
   glVertex2f(5.0, 5.0)
78
   glColor3f(0.0, 1.0, 0.0)
79
   glVertex2f(25.0, 5.0)
80
   glColor3f(0.0, 0.0, 1.0)
81
   glVertex2f(5.0, 25.0)
82
   glEnd()
83

    
84
def display():
85
   glClear(GL_COLOR_BUFFER_BIT)
86
   triangle()
87
   glFlush()
88

    
89

    
90
def reshape(w, h):
91
   glViewport(0, 0, w, h)
92
   glMatrixMode(GL_PROJECTION)
93
   glLoadIdentity()
94
   if(w <= h):
95
      gluOrtho2D(0.0, 30.0, 0.0, 30.0 * h/w)
96
   else:
97
      gluOrtho2D(0.0, 30.0 * w/h, 0.0, 30.0)
98
   glMatrixMode(GL_MODELVIEW)
99

    
100
def keyboard(key, x, y):
101
   if key == str.encode(chr(27)):
102
      sys.exit(0)
103

    
104

    
105
glutInit(sys.argv)
106
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
107
glutInitWindowSize(500, 500) 
108
glutInitWindowPosition(100, 100)
109
glutCreateWindow(b'Smooth')
110
init()
111
glutReshapeFunc(reshape)
112
glutKeyboardFunc(keyboard)
113
glutDisplayFunc(display)
114
glutMainLoop()