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.
20 int supportlogops
= 0;
23 static void Init(void)
26 glShadeModel(GL_FLAT
);
29 static void Reshape(int width
, int height
)
33 windH
= (GLint
)height
;
35 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
37 glMatrixMode(GL_PROJECTION
);
39 gluOrtho2D(0, 400, 0, 400);
40 glMatrixMode(GL_MODELVIEW
);
43 static void Key(unsigned char key
, int x
, int y
)
50 dithering
= !dithering
;
53 if (supportlogops
== 3)
54 use11ops
= (!use11ops
);
56 printf("Using GL 1.1 color logic ops.\n");
57 else printf("Using GL_EXT_blend_logic_op.\n");
66 static void Draw(void)
71 if (supportlogops
& 2)
72 glDisable(GL_COLOR_LOGIC_OP
);
74 (dithering
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
76 glClearColor(0.5, 0.6, 0.1, 1.0);
77 glClear(GL_COLOR_BUFFER_BIT
);
79 /* Draw background prims */
80 glColor3f(0.1, 0.1, 1.0);
81 glBegin(GL_TRIANGLES
);
86 glColor3f(0.5, 0.2, 0.9);
87 glBegin(GL_TRIANGLES
);
95 glBlendEquationEXT(GL_LOGIC_OP
);
97 glEnable(GL_COLOR_LOGIC_OP
);
100 /* Draw a set of rectangles across the window */
101 glColor3f(0.9, 0.2, 0.8);
102 for(i
= 0; i
< 400; i
+=60) {
105 glVertex2i(i
+50, 100);
106 glVertex2i(i
+50, 200);
110 glFlush(); /* Added by Brian Paul */
115 /* Redraw the rectangles, which should erase them */
116 for(i
= 0; i
< 400; i
+=60) {
119 glVertex2i(i
+50, 100);
120 glVertex2i(i
+50, 200);
132 static GLenum
Args(int argc
, char **argv
)
136 doubleBuffer
= GL_FALSE
;
138 for (i
= 1; i
< argc
; i
++) {
139 if (strcmp(argv
[i
], "-sb") == 0) {
140 doubleBuffer
= GL_FALSE
;
141 } else if (strcmp(argv
[i
], "-db") == 0) {
142 doubleBuffer
= GL_TRUE
;
144 printf("%s (Bad option).\n", argv
[i
]);
151 int main(int argc
, char **argv
)
155 char *extName
= "GL_EXT_blend_logic_op";
158 glutInit(&argc
, argv
);
160 if (Args(argc
, argv
) == GL_FALSE
) {
164 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400);
167 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
168 glutInitDisplayMode(type
);
170 if (glutCreateWindow("Blend XOR") == GL_FALSE
) {
176 /* Make sure blend_logic_op extension is there. */
177 s
= (char *) glGetString(GL_EXTENSIONS
);
178 version
= (char*) glGetString(GL_VERSION
);
181 if (strstr(s
,extName
)) {
184 printf("blend_logic_op extension available.\n");
186 if (strncmp(version
,"1.1",3)>=0) {
189 printf("1.1 color logic ops available.\n");
191 if (supportlogops
== 0) {
192 printf("Blend_logic_op extension and GL 1.1 not present.\n");
198 glutReshapeFunc(Reshape
);
199 glutKeyboardFunc(Key
);
200 glutDisplayFunc(Draw
);