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 static void Init(void)
23 glShadeModel(GL_FLAT
);
26 static void Reshape(int width
, int height
)
30 windH
= (GLint
)height
;
32 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
34 glMatrixMode(GL_PROJECTION
);
36 gluOrtho2D(0, 400, 0, 400);
37 glMatrixMode(GL_MODELVIEW
);
40 static void Key(unsigned char key
, int x
, int y
)
47 dithering
= !dithering
;
56 static void Draw(void)
62 (dithering
) ? glEnable(GL_DITHER
) : glDisable(GL_DITHER
);
64 glClearColor(0.5, 0.6, 0.1, 1.0);
65 glClear(GL_COLOR_BUFFER_BIT
);
67 /* Draw background prims */
68 glColor3f(0.1, 0.1, 1.0);
69 glBegin(GL_TRIANGLES
);
74 glColor3f(0.5, 0.2, 0.9);
75 glBegin(GL_TRIANGLES
);
82 glBlendEquationEXT(GL_LOGIC_OP
);
85 /* Draw a set of rectangles across the window */
86 glColor3f(0.9, 0.2, 0.8);
87 for(i
= 0; i
< 400; i
+=60) {
90 glVertex2i(i
+50, 100);
91 glVertex2i(i
+50, 200);
95 glFlush(); /* Added by Brian Paul */
100 /* Redraw the rectangles, which should erase them */
101 for(i
= 0; i
< 400; i
+=60) {
104 glVertex2i(i
+50, 100);
105 glVertex2i(i
+50, 200);
117 static GLenum
Args(int argc
, char **argv
)
121 doubleBuffer
= GL_FALSE
;
123 for (i
= 1; i
< argc
; i
++) {
124 if (strcmp(argv
[i
], "-sb") == 0) {
125 doubleBuffer
= GL_FALSE
;
126 } else if (strcmp(argv
[i
], "-db") == 0) {
127 doubleBuffer
= GL_TRUE
;
129 printf("%s (Bad option).\n", argv
[i
]);
136 int main(int argc
, char **argv
)
140 char *extName
= "GL_EXT_blend_logic_op";
142 glutInit(&argc
, argv
);
144 if (Args(argc
, argv
) == GL_FALSE
) {
148 glutInitWindowPosition(0, 0); glutInitWindowSize( 400, 400);
151 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
152 glutInitDisplayMode(type
);
154 if (glutCreateWindow("Blend XOR") == GL_FALSE
) {
158 /* Make sure blend_logic_op extension is there. */
159 s
= (char *) glGetString(GL_EXTENSIONS
);
162 if (strstr(s
,extName
) == 0) {
163 printf("Blend_logic_op extension is not present.\n");
169 glutReshapeFunc(Reshape
);
170 glutKeyboardFunc(Key
);
171 glutDisplayFunc(Draw
);