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
;
20 glGetIntegerv(GL_STENCIL_BITS
, &bits
);
21 max
= (1 << bits
) - 1;
24 glEnable(GL_STENCIL_TEST
);
25 glStencilFunc(GL_ALWAYS
, 0, ~0);
27 /* test GL_INCR (saturation) */
28 glClear(GL_STENCIL_BUFFER_BIT
);
29 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
30 printf("Testing GL_INCR...\n");
31 for (i
= 1; i
< max
+10; i
++) {
32 int expected
= (i
> max
) ? max
: i
;
34 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
36 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
37 assert(val
== expected
);
41 /* test GL_INCR_WRAP_EXT (wrap around) */
42 glClear(GL_STENCIL_BUFFER_BIT
);
43 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR_WRAP_EXT
);
44 printf("Testing GL_INCR_WRAP_EXT...\n");
45 for (i
= 1; i
< max
+10; i
++) {
46 int expected
= i
% (max
+ 1);
48 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
50 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
51 assert(val
== expected
);
57 /* test GL_INCR (saturation) */
58 glClear(GL_STENCIL_BUFFER_BIT
);
59 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR
);
60 printf("Testing GL_DECR...\n");
61 for (i
= max
-1; i
> -10; i
--) {
62 int expected
= (i
< 0) ? 0 : i
;
64 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
66 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
67 assert(val
== expected
);
71 /* test GL_INCR_WRAP_EXT (wrap-around) */
72 glClear(GL_STENCIL_BUFFER_BIT
);
73 glStencilOp(GL_KEEP
, GL_KEEP
, GL_DECR_WRAP_EXT
);
74 printf("Testing GL_DECR_WRAP_EXT...\n");
75 for (i
= max
-1; i
> -10; i
--) {
76 int expected
= (i
< 0) ? max
+ i
+ 1: i
;
78 glVertex2f(0.5, 0.5); glVertex2f(9.5, 0.5);
80 glReadPixels(0, 0, 1, 1, GL_STENCIL_INDEX
, GL_UNSIGNED_BYTE
, &val
);
81 assert(val
== expected
);
85 glDisable(GL_STENCIL_TEST
);
89 static void Display( void )
91 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
99 static void Reshape( int width
, int height
)
101 glViewport( 0, 0, width
, height
);
102 glMatrixMode( GL_PROJECTION
);
104 glOrtho(0, width
, 0, height
, -1, 1);
105 glMatrixMode( GL_MODELVIEW
);
110 static void Key( unsigned char key
, int x
, int y
)
123 static void Init( void )
125 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
126 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
127 if (!glutExtensionSupported("GL_EXT_stencil_wrap")) {
128 printf("Sorry, GL_EXT_stencil_wrap not supported.\n");
134 int main( int argc
, char *argv
[] )
136 glutInit( &argc
, argv
);
137 glutInitWindowPosition( 0, 0 );
138 glutInitWindowSize( 400, 400 );
139 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_STENCIL
);
140 glutCreateWindow(argv
[0]);
141 glutReshapeFunc( Reshape
);
142 glutKeyboardFunc( Key
);
143 glutDisplayFunc( Display
);