2 * (C) Copyright IBM Corporation 2004
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file stencil_wrap.c
28 * Simple test of GL_EXT_stencil_wrap functionality. Four squares are drawn
29 * with different stencil modes, but all should be rendered with the same
32 * \author Ian Romanick <idr@us.ibm.com>
39 static int Width
= 550;
40 static int Height
= 200;
41 static const GLfloat Near
= 5.0, Far
= 25.0;
44 static void Display( void )
51 glGetIntegerv( GL_STENCIL_BITS
, & stencil_bits
);
52 max_stencil
= (1U << stencil_bits
) - 1;
53 printf( "Stencil bits = %u, maximum stencil value = 0x%08x\n",
54 stencil_bits
, max_stencil
);
57 glClearColor( 0.2, 0.2, 0.8, 0 );
58 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
59 | GL_STENCIL_BUFFER_BIT
);
64 /* This is the "reference" square.
67 glDisable(GL_STENCIL_TEST
);
68 glTranslatef(-6.0, 0, 0);
70 glColor3f( 0.5, 0.5, 0.5 );
78 glEnable(GL_STENCIL_TEST
);
80 /* Draw the first two squares using the two non-wrap (i.e., saturate)
84 glStencilFunc(GL_ALWAYS
, 0, ~0);
85 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
87 glTranslatef(3.0, 0, 0);
89 glColor3f( 0.9, 0.9, 0.9 );
91 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
99 glStencilFunc(GL_EQUAL
, max_stencil
, ~0);
101 glColor3f( 0.5, 0.5, 0.5 );
109 glStencilFunc(GL_ALWAYS
, 0, ~0);
110 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
112 glTranslatef(3.0, 0, 0);
114 glColor3f( 0.9, 0.9, 0.9 );
116 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
124 glStencilFunc(GL_EQUAL
, 0, ~0);
126 glColor3f( 0.5, 0.5, 0.5 );
136 /* Draw the last two squares using the two wrap modes.
139 glStencilFunc(GL_ALWAYS
, 0, ~0);
140 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP
);
142 glTranslatef(3.0, 0, 0);
144 glColor3f( 0.9, 0.9, 0.9 );
146 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
154 glStencilFunc(GL_EQUAL
, 4, ~0);
156 glColor3f( 0.5, 0.5, 0.5 );
165 glStencilFunc(GL_ALWAYS
, 0, ~0);
166 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP
);
168 glTranslatef(3.0, 0, 0);
170 glColor3f( 0.9, 0.9, 0.9 );
172 for ( i
= 0 ; i
< 5 ; i
++ ) {
180 glStencilFunc(GL_EQUAL
, (max_stencil
- 4), ~0);
182 glColor3f( 0.5, 0.5, 0.5 );
197 static void Reshape( int width
, int height
)
199 GLfloat ar
= (float) width
/ (float) height
;
202 glViewport( 0, 0, width
, height
);
203 glMatrixMode( GL_PROJECTION
);
205 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
206 glMatrixMode( GL_MODELVIEW
);
208 glTranslatef( 0.0, 0.0, -15.0 );
212 static void Key( unsigned char key
, int x
, int y
)
225 static void Init( void )
227 const char * const ver_string
= (const char * const)
228 glGetString( GL_VERSION
);
230 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
231 printf("GL_VERSION = %s\n", ver_string
);
233 if ( !glutExtensionSupported("GL_EXT_stencil_wrap")
234 && (atof( ver_string
) < 1.4) ) {
235 printf("Sorry, this program requires either GL_EXT_stencil_wrap or OpenGL 1.4.\n");
239 printf("\nAll 5 squares should be the same color.\n");
240 glEnable( GL_BLEND
);
244 int main( int argc
, char *argv
[] )
246 glutInit( &argc
, argv
);
247 glutInitWindowPosition( 0, 0 );
248 glutInitWindowSize( Width
, Height
);
249 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
| GLUT_STENCIL
);
250 glutCreateWindow( "GL_EXT_stencil_wrap test" );
251 glutReshapeFunc( Reshape
);
252 glutKeyboardFunc( Key
);
253 glutDisplayFunc( Display
);