1 /* Test GL_EXT_stencil_wrap extension.
2 * This is by no means complete, just a quick check.
4 * Brian Paul 30 October 2002
14 static void RunTest(void)
16 const GLenum prim
= GL_LINES
;
21 glGetIntegerv(GL_STENCIL_BITS
, &bits
);
22 max
= (1 << bits
) - 1;
25 glEnable(GL_STENCIL_TEST
);
26 glStencilFunc(GL_ALWAYS
, 0, ~0);
28 /* test GL_INCR (saturation) */
29 glClear(GL_STENCIL_BUFFER_BIT
);
30 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
32 printf("Testing GL_INCR...\n");
33 for (i
= 1; i
< max
+10; i
++) {
34 int expected
= (i
> max
) ? max
: i
;
36 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
39 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
40 if (val
!= expected
) {
41 printf( "Failed GL_INCR test on iteration #%u "
42 "(got %u, expected %u)\n", i
, val
, expected
);
47 if ( !failed
) printf("OK!\n");
50 /* test GL_INCR_WRAP_EXT (wrap around) */
51 glClear(GL_STENCIL_BUFFER_BIT
);
52 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP_EXT
);
54 printf("Testing GL_INCR_WRAP_EXT...\n");
55 for (i
= 1; i
< max
+10; i
++) {
56 int expected
= i
% (max
+ 1);
58 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
60 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
61 if (val
!= expected
) {
62 printf( "Failed GL_INCR_WRAP test on iteration #%u "
63 "(got %u, expected %u)\n", i
, val
, expected
);
67 if ( !failed
) printf("OK!\n");
71 /* test GL_INCR (saturation) */
72 glClear(GL_STENCIL_BUFFER_BIT
);
73 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
75 printf("Testing GL_DECR...\n");
76 for (i
= max
-1; i
> -10; i
--) {
77 int expected
= (i
< 0) ? 0 : i
;
79 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
81 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
82 if (val
!= expected
) {
83 printf( "Failed GL_DECR test on iteration #%u "
84 "(got %u, expected %u)\n", max
- i
, val
, expected
);
88 if ( !failed
) printf("OK!\n");
90 /* test GL_INCR_WRAP_EXT (wrap-around) */
91 glClear(GL_STENCIL_BUFFER_BIT
);
92 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP_EXT
);
94 printf("Testing GL_DECR_WRAP_EXT...\n");
95 for (i
= max
-1; i
> -10; i
--) {
96 int expected
= (i
< 0) ? max
+ i
+ 1: i
;
98 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
100 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
101 if (val
!= expected
) {
102 printf( "Failed GL_DECR_WRAP test on iteration #%u "
103 "(got %u, expected %u)\n", max
- i
, val
, expected
);
107 if ( !failed
) printf("OK!\n");
109 glDisable(GL_STENCIL_TEST
);
113 static void Display( void )
115 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
123 static void Reshape( int width
, int height
)
125 glViewport( 0, 0, width
, height
);
126 glMatrixMode( GL_PROJECTION
);
128 glOrtho(0, width
, 0, height
, -1, 1);
129 glMatrixMode( GL_MODELVIEW
);
134 static void Key( unsigned char key
, int x
, int y
)
147 static void Init( void )
149 const char * ver_str
;
152 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
153 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
156 /* Check for both the extension string and GL version 1.4 on the
157 * outside chance that some silly vendor exports version 1.4 but doesn't
158 * export the extension string. The stencil-wrap modes are a required
162 ver_str
= glGetString( GL_VERSION
);
163 version
= (ver_str
== NULL
) ? 1.0 : strtof( ver_str
, NULL
);
165 if ( !glutExtensionSupported("GL_EXT_stencil_wrap")
166 && (version
< 1.4) ) {
167 printf("Sorry, GL_EXT_stencil_wrap not supported.\n");
173 int main( int argc
, char *argv
[] )
175 glutInit( &argc
, argv
);
176 glutInitWindowPosition( 0, 0 );
177 glutInitWindowSize( 400, 400 );
178 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_STENCIL
);
179 glutCreateWindow(argv
[0]);
180 glutReshapeFunc( Reshape
);
181 glutKeyboardFunc( Key
);
182 glutDisplayFunc( Display
);