gallium: add target-helpers/wrap_screen.c to C_SOURCES
[mesa/mesa-lb.git] / progs / samples / cursor.c
blobde8fc58556c83a3de288b767d3f8752566eece69
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 GLenum rgb, doubleBuffer, windType;
32 int windX, windY;
33 int cursor;
36 #include "tkmap.c"
38 static void Init(void)
40 cursor = 0;
41 glutSetCursor(cursor);
42 glClearColor(0.0, 0.0, 0.0, 0.0);
43 glClearIndex(0.0);
46 static void Reshape(int width, int height)
49 windX = width;
50 windY = height;
51 glViewport(0, 0, windX, windY);
53 glMatrixMode(GL_PROJECTION);
54 glLoadIdentity();
55 gluOrtho2D(0, windX, 0, windY);
56 glMatrixMode(GL_MODELVIEW);
59 static void Key(unsigned char key, int x, int y)
62 switch (key) {
63 case 27:
64 exit(1);
65 case 32:
66 cursor++;
67 if (cursor > 19) {
68 cursor = 0;
70 glutSetCursor(cursor);
74 static void Draw(void)
77 glClear(GL_COLOR_BUFFER_BIT);
79 glBegin(GL_POLYGON);
80 SetColor(COLOR_BLACK);
81 glVertex2i(0, 0);
82 SetColor(COLOR_RED);
83 glVertex2i(windX, 0);
84 SetColor(COLOR_GREEN);
85 glVertex2i(windX, windY);
86 SetColor(COLOR_BLUE);
87 glVertex2i(0, windY);
88 glEnd();
90 glFlush();
92 if (doubleBuffer) {
93 glutSwapBuffers();
97 static GLenum Args(int argc, char **argv)
99 GLint i;
101 rgb = GL_TRUE;
102 doubleBuffer = GL_FALSE;
104 for (i = 1; i < argc; i++) {
105 if (strcmp(argv[i], "-ci") == 0) {
106 rgb = GL_FALSE;
107 } else if (strcmp(argv[i], "-rgb") == 0) {
108 rgb = GL_TRUE;
109 } else if (strcmp(argv[i], "-sb") == 0) {
110 doubleBuffer = GL_FALSE;
111 } else if (strcmp(argv[i], "-db") == 0) {
112 doubleBuffer = GL_TRUE;
113 } else {
114 printf("%s (Bad option).\n", argv[i]);
115 return GL_FALSE;
118 return GL_TRUE;
121 int main(int argc, char **argv)
123 glutInit(&argc, argv);
125 if (Args(argc, argv) == GL_FALSE) {
126 exit(1);
129 windX = 300;
130 windY = 300;
131 glutInitWindowPosition(0, 0); glutInitWindowSize( windX, windY);
133 windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
134 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
135 glutInitDisplayMode(windType);
137 if (glutCreateWindow("Cursor Test") == GL_FALSE) {
138 exit(1);
141 InitMap();
143 Init();
145 glutReshapeFunc(Reshape);
146 glutKeyboardFunc(Key);
147 glutDisplayFunc(Draw);
148 glutMainLoop();
149 return 0;