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
17 #define GL_GLEXT_PROTOTYPES
25 int supportlogops
= 0;
28 static void Init(void)
31 glShadeModel(GL_FLAT
);
34 static void Reshape(int width
, int height
)
38 windH
= (GLint
)height
;
40 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
42 glMatrixMode(GL_PROJECTION
);
44 gluOrtho2D(0, 400, 0, 400);
45 glMatrixMode(GL_MODELVIEW
);
48 static void Key(unsigned char key
, int x
, int y
)
55 dithering
= !dithering
;
58 if (supportlogops
== 3)
59 use11ops
= (!use11ops
);
61 printf("Using GL 1.1 color logic ops.\n");
62 else printf("Using GL_EXT_blend_logic_op.\n");
71 static void Draw(void)
76 if (supportlogops
& 2)
77 glDisable(GL_COLOR_LOGIC_OP
);
79 (dithering
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
81 glClearColor(0.5, 0.6, 0.1, 1.0);
82 glClear(GL_COLOR_BUFFER_BIT
);
84 /* Draw background prims */
85 glColor3f(0.1, 0.1, 1.0);
86 glBegin(GL_TRIANGLES
);
91 glColor3f(0.5, 0.2, 0.9);
92 glBegin(GL_TRIANGLES
);
100 glBlendEquationEXT(GL_LOGIC_OP
);
102 glEnable(GL_COLOR_LOGIC_OP
);
105 /* Draw a set of rectangles across the window */
106 glColor3f(0.9, 0.2, 0.8);
107 for(i
= 0; i
< 400; i
+=60) {
110 glVertex2i(i
+50, 100);
111 glVertex2i(i
+50, 200);
115 glFlush(); /* Added by Brian Paul */
120 /* Redraw the rectangles, which should erase them */
121 for(i
= 0; i
< 400; i
+=60) {
124 glVertex2i(i
+50, 100);
125 glVertex2i(i
+50, 200);
137 static GLenum
Args(int argc
, char **argv
)
141 doubleBuffer
= GL_FALSE
;
143 for (i
= 1; i
< argc
; i
++) {
144 if (strcmp(argv
[i
], "-sb") == 0) {
145 doubleBuffer
= GL_FALSE
;
146 } else if (strcmp(argv
[i
], "-db") == 0) {
147 doubleBuffer
= GL_TRUE
;
149 printf("%s (Bad option).\n", argv
[i
]);
156 int main(int argc
, char **argv
)
160 char *extName
= "GL_EXT_blend_logic_op";
163 glutInit(&argc
, argv
);
165 if (Args(argc
, argv
) == GL_FALSE
) {
169 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400);
172 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
173 glutInitDisplayMode(type
);
175 if (glutCreateWindow("Blend XOR") == GL_FALSE
) {
179 /* Make sure blend_logic_op extension is there. */
180 s
= (char *) glGetString(GL_EXTENSIONS
);
181 version
= (char*) glGetString(GL_VERSION
);
184 if (strstr(s
,extName
)) {
187 printf("blend_logic_op extension available.\n");
189 if (strncmp(version
,"1.1",3)>=0) {
192 printf("1.1 color logic ops available.\n");
194 if (supportlogops
== 0) {
195 printf("Blend_logic_op extension and GL 1.1 not present.\n");
201 glutReshapeFunc(Reshape
);
202 glutKeyboardFunc(Key
);
203 glutDisplayFunc(Draw
);