1/*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3 *
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.
11 *
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.
16 *
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.
23 */
24
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28#include "glut_wrap.h"
29
30
31GLenum rgb, doubleBuffer, windType;
32int windX, windY;
33int cursor;
34
35
36#include "tkmap.c"
37
38static void Init(void)
39{
40    cursor = 0;
41    glutSetCursor(cursor);
42    glClearColor(0.0, 0.0, 0.0, 0.0);
43    glClearIndex(0.0);
44}
45
46static void Reshape(int width, int height)
47{
48
49    windX = width;
50    windY = height;
51    glViewport(0, 0, windX, windY);
52
53    glMatrixMode(GL_PROJECTION);
54    glLoadIdentity();
55    gluOrtho2D(0, windX, 0, windY);
56    glMatrixMode(GL_MODELVIEW);
57}
58
59static void Key(unsigned char key, int x, int y)
60{
61
62    switch (key) {
63      case 27:
64        exit(1);
65      case 32:
66	cursor++;
67	if (cursor > 19) {
68	    cursor = 0;
69	}
70	glutSetCursor(cursor);
71    }
72}
73
74static void Draw(void)
75{
76
77    glClear(GL_COLOR_BUFFER_BIT);
78
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();
89
90    glFlush();
91
92    if (doubleBuffer) {
93	glutSwapBuffers();
94    }
95}
96
97static GLenum Args(int argc, char **argv)
98{
99    GLint i;
100
101    rgb = GL_TRUE;
102    doubleBuffer = GL_FALSE;
103
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;
116	}
117    }
118    return GL_TRUE;
119}
120
121int main(int argc, char **argv)
122{
123    glutInit(&argc, argv);
124
125    if (Args(argc, argv) == GL_FALSE) {
126	exit(1);
127    }
128
129    windX = 300;
130    windY = 300;
131    glutInitWindowPosition(0, 0); glutInitWindowSize( windX, windY);
132
133    windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
134    windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
135    glutInitDisplayMode(windType);
136
137    if (glutCreateWindow("Cursor Test") == GL_FALSE) {
138	exit(1);
139    }
140
141    InitMap();
142
143    Init();
144
145    glutReshapeFunc(Reshape);
146    glutKeyboardFunc(Key);
147    glutDisplayFunc(Draw);
148    glutMainLoop();
149	return 0;
150}
151