Revert "wglgears: show stereo-option in usage"
[mesa-demos.git] / src / trivial / line-xor.c
blob561f0cb5036bc3cba5558b66db137bde526d7547
1 /*
2 * Draw lines in XOR mode.
3 * Note that the last pixel in a line segment should not be drawn by GL
4 * so that pixels aren't touched twice at the shared vertex of connected lines.
6 * Brian Paul
7 * 7 Oct 2010
8 */
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include "glut_wrap.h"
17 static GLboolean xor = GL_TRUE;
20 static void
21 Reshape(int width, int height)
23 glViewport(0, 0, (GLint)width, (GLint)height);
25 glMatrixMode(GL_PROJECTION);
26 glLoadIdentity();
27 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
28 glMatrixMode(GL_MODELVIEW);
32 static void
33 Key(unsigned char key, int x, int y)
35 if (key == 'x') {
36 xor = !xor;
37 printf("XOR mode: %s\n", xor ? "on" : "off");
39 else if (key == 27)
40 exit(0);
41 glutPostRedisplay();
45 static void
46 Draw(void)
48 glClear(GL_COLOR_BUFFER_BIT);
50 glLogicOp(GL_XOR);
51 if (xor)
52 glEnable(GL_COLOR_LOGIC_OP);
53 else
54 glDisable(GL_COLOR_LOGIC_OP);
56 glColor3f(0, 1, 0);
58 /* outer line rect */
59 glBegin(GL_LINE_LOOP);
60 glVertex2f(-0.9, -0.9);
61 glVertex2f( 0.9, -0.9);
62 glVertex2f( 0.9, 0.9);
63 glVertex2f(-0.9, 0.9);
64 glEnd();
66 /* middle line rect */
67 glBegin(GL_LINE_STRIP);
68 glVertex2f(-0.8, -0.8);
69 glVertex2f( 0.8, -0.8);
70 glVertex2f( 0.8, 0.8);
71 glVertex2f(-0.8, 0.8);
72 glVertex2f(-0.8, -0.8);
73 glEnd();
75 /* inner line rect */
76 glBegin(GL_LINES);
77 glVertex2f(-0.7, -0.7);
78 glVertex2f( 0.7, -0.7);
80 glVertex2f( 0.7, -0.7);
81 glVertex2f( 0.7, 0.7);
83 glVertex2f( 0.7, 0.7);
84 glVertex2f(-0.7, 0.7);
86 glVertex2f(-0.7, 0.7);
87 glVertex2f(-0.7, -0.7);
88 glEnd();
90 /* inner + pattern */
91 glBegin(GL_LINES);
92 glVertex2f(-0.6, 0.0);
93 glVertex2f( 0.6, 0.0);
94 glVertex2f( 0.0, 0.6);
95 glVertex2f( 0.0, -0.6);
96 glEnd();
99 glutSwapBuffers();
104 main(int argc, char **argv)
106 glutInit(&argc, argv);
108 glutInitWindowSize(250, 250);
110 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
111 glutCreateWindow(argv[0]);
112 glutReshapeFunc(Reshape);
113 glutKeyboardFunc(Key);
114 glutDisplayFunc(Draw);
116 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
117 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
118 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
119 fprintf(stderr, "NOTE: there should be no pixels missing at the corners"
120 " of the line loops.\n");
121 fprintf(stderr, "There should be a missing pixel at the center of the '+'.\n");
122 fprintf(stderr, "Resize the window to check for any pixel drop-outs.\n");
123 fprintf(stderr, "Press 'x' to toggle XOR mode on/off.\n");
125 glutMainLoop();
127 return 0;