2 ** blendxor.c - Demonstrates the use of the blend_logic_op
3 ** extension to draw hilights. Using XOR to draw the same
4 ** image twice restores the background to its original value.
16 #define GL_GLEXT_LEGACY
24 static void Init(void)
27 glShadeModel(GL_FLAT
);
30 static void Reshape(int width
, int height
)
34 windH
= (GLint
)height
;
36 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
38 glMatrixMode(GL_PROJECTION
);
40 gluOrtho2D(0, 400, 0, 400);
41 glMatrixMode(GL_MODELVIEW
);
44 static void Key(unsigned char key
, int x
, int y
)
51 dithering
= !dithering
;
60 static void Draw(void)
66 (dithering
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
68 glClearColor(0.5, 0.6, 0.1, 1.0);
69 glClear(GL_COLOR_BUFFER_BIT
);
71 /* Draw background prims */
72 glColor3f(0.1, 0.1, 1.0);
73 glBegin(GL_TRIANGLES
);
78 glColor3f(0.5, 0.2, 0.9);
79 glBegin(GL_TRIANGLES
);
86 glBlendEquationEXT(GL_LOGIC_OP
);
89 /* Draw a set of rectangles across the window */
90 glColor3f(0.9, 0.2, 0.8);
91 for(i
= 0; i
< 400; i
+=60) {
94 glVertex2i(i
+50, 100);
95 glVertex2i(i
+50, 200);
99 glFlush(); /* Added by Brian Paul */
104 /* Redraw the rectangles, which should erase them */
105 for(i
= 0; i
< 400; i
+=60) {
108 glVertex2i(i
+50, 100);
109 glVertex2i(i
+50, 200);
121 static GLenum
Args(int argc
, char **argv
)
125 doubleBuffer
= GL_FALSE
;
127 for (i
= 1; i
< argc
; i
++) {
128 if (strcmp(argv
[i
], "-sb") == 0) {
129 doubleBuffer
= GL_FALSE
;
130 } else if (strcmp(argv
[i
], "-db") == 0) {
131 doubleBuffer
= GL_TRUE
;
133 printf("%s (Bad option).\n", argv
[i
]);
140 int main(int argc
, char **argv
)
144 char *extName
= "GL_EXT_blend_logic_op";
146 glutInit(&argc
, argv
);
148 if (Args(argc
, argv
) == GL_FALSE
) {
152 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400);
155 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
156 glutInitDisplayMode(type
);
158 if (glutCreateWindow("Blend XOR") == GL_FALSE
) {
162 /* Make sure blend_logic_op extension is there. */
163 s
= (char *) glGetString(GL_EXTENSIONS
);
166 if (strstr(s
,extName
) == 0) {
167 printf("Blend_logic_op extension is not present.\n");
173 glutReshapeFunc(Reshape
);
174 glutKeyboardFunc(Key
);
175 glutDisplayFunc(Draw
);