gallium: add target-helpers/wrap_screen.c to C_SOURCES
[mesa/mesa-lb.git] / progs / samples / point.c
blob4cb6ad7d517639d3fd9328f3036de22960bf70bc
1 /*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13 * ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <GL/glut.h>
31 #define CI_RED COLOR_RED
32 #define CI_ANTI_ALIAS_GREEN 16
33 #define CI_ANTI_ALIAS_YELLOW 32
34 #define CI_ANTI_ALIAS_RED 48
37 GLenum rgb, doubleBuffer, windType;
38 GLint windW, windH;
40 #include "tkmap.c"
42 GLenum mode;
43 GLint size;
44 float point[3] = {
45 1.0, 1.0, 0.0
49 static void Init(void)
51 GLint i;
53 glClearColor(0.0, 0.0, 0.0, 0.0);
55 glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
57 if (!rgb) {
58 for (i = 0; i < 16; i++) {
59 glutSetColor(i+CI_ANTI_ALIAS_RED, i/15.0, 0.0, 0.0);
60 glutSetColor(i+CI_ANTI_ALIAS_YELLOW, i/15.0, i/15.0, 0.0);
61 glutSetColor(i+CI_ANTI_ALIAS_GREEN, 0.0, i/15.0, 0.0);
65 mode = GL_FALSE;
66 size = 1;
69 static void Reshape(int width, int height)
72 windW = (GLint)width;
73 windH = (GLint)height;
75 glViewport(0, 0, width, height);
77 glMatrixMode(GL_PROJECTION);
78 glLoadIdentity();
79 gluOrtho2D(-windW/2, windW/2, -windH/2, windH/2);
80 glMatrixMode(GL_MODELVIEW);
83 static void Key2(int key, int x, int y)
86 switch (key) {
87 case GLUT_KEY_LEFT:
88 point[0] -= 0.25;
89 break;
90 case GLUT_KEY_RIGHT:
91 point[0] += 0.25;
92 break;
93 case GLUT_KEY_UP:
94 point[1] += 0.25;
95 break;
96 case GLUT_KEY_DOWN:
97 point[1] -= 0.25;
98 break;
99 default:
100 return;
103 glutPostRedisplay();
106 static void Key(unsigned char key, int x, int y)
109 switch (key) {
110 case 27:
111 exit(1);
112 case '1':
113 mode = !mode;
114 break;
115 case 'W':
116 size++;
117 break;
118 case 'w':
119 size--;
120 if (size < 1) {
121 size = 1;
123 break;
124 default:
125 return;
128 glutPostRedisplay();
131 static void Draw(void)
134 glClear(GL_COLOR_BUFFER_BIT);
136 SetColor(COLOR_YELLOW);
137 glBegin(GL_LINE_STRIP);
138 glVertex2f(-windW/2, 0);
139 glVertex2f(windW/2, 0);
140 glEnd();
141 glBegin(GL_LINE_STRIP);
142 glVertex2f(0, -windH/2);
143 glVertex2f(0, windH/2);
144 glEnd();
146 if (mode) {
147 glEnable(GL_BLEND);
148 glEnable(GL_POINT_SMOOTH);
149 } else {
150 glDisable(GL_BLEND);
151 glDisable(GL_POINT_SMOOTH);
154 glPointSize(size);
155 if (mode) {
156 (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_ANTI_ALIAS_RED);
157 } else {
158 (rgb) ? glColor3f(1.0, 0.0, 0.0) : glIndexf(CI_RED);
160 glBegin(GL_POINTS);
161 glVertex3fv(point);
162 glEnd();
164 glDisable(GL_POINT_SMOOTH);
165 glDisable(GL_BLEND);
167 glPointSize(1);
168 SetColor(COLOR_GREEN);
169 glBegin(GL_POINTS);
170 glVertex3fv(point);
171 glEnd();
173 glFlush();
175 if (doubleBuffer) {
176 glutSwapBuffers();
180 static GLenum Args(int argc, char **argv)
182 GLint i;
184 rgb = GL_TRUE;
185 doubleBuffer = GL_FALSE;
187 for (i = 1; i < argc; i++) {
188 if (strcmp(argv[i], "-ci") == 0) {
189 rgb = GL_FALSE;
190 } else if (strcmp(argv[i], "-rgb") == 0) {
191 rgb = GL_TRUE;
192 } else if (strcmp(argv[i], "-sb") == 0) {
193 doubleBuffer = GL_FALSE;
194 } else if (strcmp(argv[i], "-db") == 0) {
195 doubleBuffer = GL_TRUE;
196 } else {
197 printf("%s (Bad option).\n", argv[i]);
198 return GL_FALSE;
201 return GL_TRUE;
204 int main(int argc, char **argv)
206 glutInit(&argc, argv);
208 if (Args(argc, argv) == GL_FALSE) {
209 exit(1);
212 windW = 300;
213 windH = 300;
214 glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
216 windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
217 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
218 glutInitDisplayMode(windType);
220 if (glutCreateWindow("Point Test") == GL_FALSE) {
221 exit(1);
224 InitMap();
226 Init();
228 glutReshapeFunc(Reshape);
229 glutKeyboardFunc(Key);
230 glutSpecialFunc(Key2);
231 glutDisplayFunc(Draw);
232 glutMainLoop();
233 return 0;