~mcfletch/openglcontext/trunk : /tests/redbook_alpha.py (revision 351)

Line Revision Contents
1 1
#! /usr/bin/env python
2
"""Demonstration of effect of rendering order on blended polys
3
4
/*
5
 * Copyright (c) 1993-1999, Silicon Graphics, Inc.
6
 * ALL RIGHTS RESERVED 
7
 * Permission to use, copy, modify, and distribute this software for 
8
 * any purpose and without fee is hereby granted, provided that the above
9
 * copyright notice appear in all copies and that both the copyright notice
10
 * and this permission notice appear in supporting documentation, and that 
11
 * the name of Silicon Graphics, Inc. not be used in advertising
12
 * or publicity pertaining to distribution of the software without specific,
13
 * written prior permission. 
14
 *
15
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
19
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
24
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
27
 * 
28
 * US Government Users Restricted Rights 
29
 * Use, duplication, or disclosure by the Government is subject to
30
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
 * clause at DFARS 252.227-7013 and/or in similar or successor
33
 * clauses in the FAR or the DOD or NASA FAR Supplement.
34
 * Unpublished-- rights reserved under the copyright laws of the
35
 * United States.  Contractor/manufacturer is Silicon Graphics,
36
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
37
 *
38
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
39
 */
40
41
/*
42
 *  alpha.c
43
 *  This program draws several overlapping filled polygons
44
 *  to demonstrate the effect order has on alpha blending results.
45
 *  Use the 't' key to toggle the order of drawing polygons.
46
 */
47
"""
48
from OpenGLContext import testingcontext
49 296
BaseContext = testingcontext.getInteractive()
50 1
from OpenGLContext import context
51
from OpenGL.GL import *
52
from OpenGLContext.arrays import array
53
import string
54
55
56
class TestContext( BaseContext ):
57
	"""Red Book alpha.c
58
	Demonstrates the effects of alpha blending
59
	Copyright (c) 1993-1999, Silicon Graphics, Inc. ALL RIGHTS RESERVED 
60
	"""
61
	initialPosition = (0,0,2)
62
	def OnInit( self ):
63
		self.leftFirst = 1
64
		self.addEventHandler( 'keypress', name='f', function = self.OnSwitch )
65
		print 'Press "f" to switch polygon order'
66
	def OnSwitch( self, event ):
67
		"""Switch order of triangles"""
68
		self.leftFirst = not self.leftFirst
69
		self.triggerRedraw(1)
70
	def SetupDisplay( self, mode = None ):
71
		"""Setup display for display for the given mode"""
72
		### NOTE:
73
		### required because the context enables by default!
74
		glDisable(GL_DEPTH_TEST);
75
	def Render( self, mode = 0):
76
		BaseContext.Render( self, mode )
77
		glEnable (GL_BLEND);
78
		glDisable( GL_LIGHTING )
79
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
80
		glShadeModel (GL_FLAT);
81
82
		if self.leftFirst:
83
			self.left();
84
			self.right();
85
		else:
86
			self.right();
87
			self.left();
88
89
90
	def left( self ):
91
		"""draw yellow triangle on LHS of screen"""
92
		glBegin (GL_TRIANGLES);
93
		glColor4f(1.0, 1.0, 0.0, 0.5);
94
		glVertex3f(0.1, 0.9, 0.0);
95
		glVertex3f(0.1, 0.1, 0.0);
96
		glVertex3f(0.7, 0.5, 0.0);
97
		glEnd();
98
	def right( self ):
99
		"""draw cyan triangle on RHS of screen"""
100
		glBegin (GL_TRIANGLES);
101
		glColor4f(0.0, 1.0, 1.0, 0.5);
102
		glVertex3f(0.9, 0.9, 0.0); 
103
		glVertex3f(0.3, 0.5, 0.0); 
104
		glVertex3f(0.9, 0.1, 0.0); 
105
		glEnd();
106
107
108
if __name__ == "__main__":
109 296
	TestContext.ContextMainLoop()
110 1
111

Loggerhead 1.10 is a web-based interface for Bazaar branches