1 /* Test GL_EXT_stencil_wrap extension.
2 * This is by no means complete, just a quick check.
4 * Brian Paul 30 October 2002
12 #include "glut_wrap.h"
16 static void RunTest(void)
18 const GLenum prim
= GL_QUAD_STRIP
;
24 glGetIntegerv(GL_STENCIL_BITS
, &bits
);
25 max
= (1 << bits
) - 1;
28 glEnable(GL_STENCIL_TEST
);
29 glStencilFunc(GL_ALWAYS
, 0, ~0);
33 glClear(GL_STENCIL_BUFFER_BIT
);
34 glStencilOp(GL_KEEP
, GL_KEEP
, GL_KEEP
);
36 printf("Testing GL_KEEP...\n");
44 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
45 if (val
!= expected
) {
46 printf("Failed GL_KEEP test(got %u, expected %u)\n", val
, expected
);
54 glClear(GL_STENCIL_BUFFER_BIT
);
55 glStencilOp(GL_KEEP
, GL_KEEP
, GL_ZERO
);
57 printf("Testing GL_ZERO...\n");
65 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
66 if (val
!= expected
) {
67 printf("Failed GL_ZERO test(got %u, expected %u)\n", val
, expected
);
75 glClear(GL_STENCIL_BUFFER_BIT
);
76 glStencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
78 printf("Testing GL_REPLACE...\n");
86 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
87 if (val
!= expected
) {
88 printf("Failed GL_REPLACE test(got %u, expected %u)\n", val
, expected
);
94 /* test GL_INCR (saturation) */
96 glClear(GL_STENCIL_BUFFER_BIT
);
97 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
99 printf("Testing GL_INCR...\n");
100 for (i
= 1; i
< max
+10; i
++) {
101 expected
= (i
> max
) ? max
: i
;
103 glVertex2f(0, 0); glVertex2f(10, 0);
104 glVertex2f(0, 10); glVertex2f(10, 10);
107 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
108 if (val
!= expected
) {
109 printf( "Failed GL_INCR test on iteration #%u "
110 "(got %u, expected %u)\n", i
, val
, expected
);
117 /* test GL_DECR (saturation) */
119 glClear(GL_STENCIL_BUFFER_BIT
);
120 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
122 printf("Testing GL_DECR...\n");
123 for (i
= max
-1; i
> -10; i
--) {
124 expected
= (i
< 0) ? 0 : i
;
126 glVertex2f(0, 0); glVertex2f(10, 0);
127 glVertex2f(0, 10); glVertex2f(10, 10);
129 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
130 if (val
!= expected
) {
131 printf( "Failed GL_DECR test on iteration #%u "
132 "(got %u, expected %u)\n", max
- i
, val
, expected
);
141 glClear(GL_STENCIL_BUFFER_BIT
);
142 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INVERT
);
144 printf("Testing GL_INVERT...\n");
152 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
153 if (val
!= expected
) {
154 printf("Failed GL_INVERT test(got %u, expected %u)\n", val
, expected
);
162 /* test GL_INCR_WRAP_EXT (wrap around) */
164 glClear(GL_STENCIL_BUFFER_BIT
);
165 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP_EXT
);
167 printf("Testing GL_INCR_WRAP_EXT...\n");
168 for (i
= 1; i
< max
+10; i
++) {
169 expected
= i
% (max
+ 1);
171 glVertex2f(0, 0); glVertex2f(10, 0);
172 glVertex2f(0, 10); glVertex2f(10, 10);
174 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
175 if (val
!= expected
) {
176 printf( "Failed GL_INCR_WRAP test on iteration #%u "
177 "(got %u, expected %u)\n", i
, val
, expected
);
184 /* test GL_DECR_WRAP_EXT (wrap-around) */
186 glClear(GL_STENCIL_BUFFER_BIT
);
187 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP_EXT
);
189 printf("Testing GL_DECR_WRAP_EXT...\n");
190 for (i
= max
-1; i
> -10; i
--) {
191 expected
= (i
< 0) ? max
+ i
+ 1: i
;
193 glVertex2f(0, 0); glVertex2f(10, 0);
194 glVertex2f(0, 10); glVertex2f(10, 10);
196 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
197 if (val
!= expected
) {
198 printf( "Failed GL_DECR_WRAP test on iteration #%u "
199 "(got %u, expected %u)\n", max
- i
, val
, expected
);
207 glDisable(GL_STENCIL_TEST
);
211 static void Display( void )
213 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
221 static void Reshape( int width
, int height
)
223 glViewport( 0, 0, width
, height
);
224 glMatrixMode( GL_PROJECTION
);
226 glOrtho(0, width
, 0, height
, -1, 1);
227 glMatrixMode( GL_MODELVIEW
);
232 static void Key( unsigned char key
, int x
, int y
)
245 static void Init( void )
247 const char * ver_str
;
250 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
251 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
254 /* Check for both the extension string and GL version 1.4 on the
255 * outside chance that some vendor exports version 1.4 but doesn't
256 * export the extension string. The stencil-wrap modes are a required
260 ver_str
= (char *) glGetString( GL_VERSION
);
261 version
= (ver_str
== NULL
) ? 1.0 : atof( ver_str
);
263 wrapping
= (glutExtensionSupported("GL_EXT_stencil_wrap") || (version
>= 1.4));
265 printf("GL_EXT_stencil_wrap not supported. Only testing the rest.\n");
269 int main( int argc
, char *argv
[] )
271 glutInit( &argc
, argv
);
272 glutInitWindowPosition( 0, 0 );
273 glutInitWindowSize( 400, 400 );
274 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_STENCIL
);
275 glutCreateWindow(argv
[0]);
277 glutReshapeFunc( Reshape
);
278 glutKeyboardFunc( Key
);
279 glutDisplayFunc( Display
);