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>
40 static int Width
= 550;
41 static int Height
= 200;
42 static const GLfloat Near
= 5.0, Far
= 25.0;
45 static void Display( void )
52 glGetIntegerv( GL_STENCIL_BITS
, & stencil_bits
);
53 max_stencil
= (1U << stencil_bits
) - 1;
54 printf( "Stencil bits = %u, maximum stencil value = 0x%08x\n",
55 stencil_bits
, max_stencil
);
58 glClearColor( 0.2, 0.2, 0.8, 0 );
59 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
60 | GL_STENCIL_BUFFER_BIT
);
65 /* This is the "reference" square.
68 glDisable(GL_STENCIL_TEST
);
69 glTranslatef(-6.0, 0, 0);
71 glColor3f( 0.5, 0.5, 0.5 );
79 glEnable(GL_STENCIL_TEST
);
81 /* Draw the first two squares using the two non-wrap (i.e., saturate)
85 glStencilFunc(GL_ALWAYS
, 0, ~0);
86 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
88 glTranslatef(3.0, 0, 0);
90 glColor3f( 0.9, 0.9, 0.9 );
92 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
100 glStencilFunc(GL_EQUAL
, max_stencil
, ~0);
102 glColor3f( 0.5, 0.5, 0.5 );
110 glStencilFunc(GL_ALWAYS
, 0, ~0);
111 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
113 glTranslatef(3.0, 0, 0);
115 glColor3f( 0.9, 0.9, 0.9 );
117 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
125 glStencilFunc(GL_EQUAL
, 0, ~0);
127 glColor3f( 0.5, 0.5, 0.5 );
137 /* Draw the last two squares using the two wrap modes.
140 glStencilFunc(GL_ALWAYS
, 0, ~0);
141 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP
);
143 glTranslatef(3.0, 0, 0);
145 glColor3f( 0.9, 0.9, 0.9 );
147 for ( i
= 0 ; i
< (max_stencil
+ 5) ; i
++ ) {
155 glStencilFunc(GL_EQUAL
, 4, ~0);
157 glColor3f( 0.5, 0.5, 0.5 );
166 glStencilFunc(GL_ALWAYS
, 0, ~0);
167 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP
);
169 glTranslatef(3.0, 0, 0);
171 glColor3f( 0.9, 0.9, 0.9 );
173 for ( i
= 0 ; i
< 5 ; i
++ ) {
181 glStencilFunc(GL_EQUAL
, (max_stencil
- 4), ~0);
183 glColor3f( 0.5, 0.5, 0.5 );
198 static void Reshape( int width
, int height
)
200 GLfloat ar
= (float) width
/ (float) height
;
203 glViewport( 0, 0, width
, height
);
204 glMatrixMode( GL_PROJECTION
);
206 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
207 glMatrixMode( GL_MODELVIEW
);
209 glTranslatef( 0.0, 0.0, -15.0 );
213 static void Key( unsigned char key
, int x
, int y
)
226 static void Init( void )
228 const char * const ver_string
= (const char * const)
229 glGetString( GL_VERSION
);
231 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
232 printf("GL_VERSION = %s\n", ver_string
);
234 if ( !glutExtensionSupported("GL_EXT_stencil_wrap")
235 && (atof( ver_string
) < 1.4) ) {
236 printf("Sorry, this program requires either GL_EXT_stencil_wrap or OpenGL 1.4.\n");
240 printf("\nAll 5 squares should be the same color.\n");
241 glEnable( GL_BLEND
);
245 int main( int argc
, char *argv
[] )
247 glutInit( &argc
, argv
);
248 glutInitWindowPosition( 0, 0 );
249 glutInitWindowSize( Width
, Height
);
250 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
| GLUT_STENCIL
);
251 glutCreateWindow( "GL_EXT_stencil_wrap test" );
253 glutReshapeFunc( Reshape
);
254 glutKeyboardFunc( Key
);
255 glutDisplayFunc( Display
);