blob: c08089b9dd7a50634cbd7146705ccd3dcbce206f [file] [log] [blame]
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +01001/*
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 <GL/glut.h>
29
30GLenum doubleBuffer = 1;
31int win;
Keith Whitwellc691f962009-04-20 15:50:44 +010032static float tx = 0;
33static float ty = 0;
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010034static float tw = 0;
35static float th = 0;
36
37static float win_width = 250;
38static float win_height = 250;
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010039
40static void Init(void)
41{
42 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
43 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
44 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
Keith Whitwelleb9801c2009-03-24 16:35:29 +000045 fflush(stderr);
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010046
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010047 glClearColor(0, 0, 0, 0.0);
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010048}
49
50static void Reshape(int width, int height)
51{
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010052 win_width = width;
53 win_height = height;
54 glutPostRedisplay();
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010055}
56
Keith Whitwellc691f962009-04-20 15:50:44 +010057
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010058static void Key(unsigned char key, int x, int y)
59{
60 switch (key) {
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010061 case 27:
62 exit(0);
63 case 'w':
64 tw += 1.0;
65 break;
66 case 'W':
67 tw -= 1.0;
68 break;
69 case 'h':
70 th += 1.0;
71 break;
72 case 'H':
73 th -= 1.0;
74 break;
75
76 default:
77 break;
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010078 }
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010079 glutPostRedisplay();
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010080}
81
Keith Whitwellc691f962009-04-20 15:50:44 +010082
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010083static void Draw(void)
84{
Keith Whitwellc691f962009-04-20 15:50:44 +010085 int i;
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010086 float w = tw + win_width;
87 float h = th + win_height;
Keith Whitwellc691f962009-04-20 15:50:44 +010088
Keith Whitwell6bfcffa2009-04-20 17:30:53 +010089 fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h);
Keith Whitwellc691f962009-04-20 15:50:44 +010090 fflush(stderr);
91
92 glMatrixMode(GL_PROJECTION);
93 glLoadIdentity();
94 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
95 glMatrixMode(GL_MODELVIEW);
96
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +010097 glClear(GL_COLOR_BUFFER_BIT);
98
Keith Whitwellc691f962009-04-20 15:50:44 +010099
Keith Whitwell6bfcffa2009-04-20 17:30:53 +0100100 /***********************************************************************
101 * Should be clipped to be no larger than the triangles:
102 */
103 glViewport(tx, ty, w, h);
104 glBegin(GL_POLYGON);
105 glColor3f(.5,.5,1);
106 glVertex3f(-2, -2, -30.0);
107 glVertex3f(-2, 2, -30.0);
108 glVertex3f(2, 2, -30.0);
109 glVertex3f(2, -2, -30.0);
110 glEnd();
111
112 /***********************************************************************
113 */
114 glViewport(0, 0, win_width, win_height);
Keith Whitwellc691f962009-04-20 15:50:44 +0100115 glBegin(GL_LINES);
116 glColor3f(1,1,0);
117 glVertex3f(-1, 0, -30.0);
118 glVertex3f(1, 0, -30.0);
119
120 glVertex3f(0, -1, -30.0);
121 glVertex3f(0, 1, -30.0);
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +0100122 glEnd();
123
Keith Whitwellc691f962009-04-20 15:50:44 +0100124
Keith Whitwell6bfcffa2009-04-20 17:30:53 +0100125 /***********************************************************************
Keith Whitwellc691f962009-04-20 15:50:44 +0100126 */
Keith Whitwell6bfcffa2009-04-20 17:30:53 +0100127 glViewport(tx, ty, w, h);
Keith Whitwellc691f962009-04-20 15:50:44 +0100128 glBegin(GL_TRIANGLES);
129 glColor3f(1,0,0);
130 glVertex3f(-1, -1, -30.0);
131 glVertex3f(0, -1, -30.0);
132 glVertex3f(-.5, -.5, -30.0);
133
134 glColor3f(1,1,1);
135 glVertex3f(0, -1, -30.0);
136 glVertex3f(1, -1, -30.0);
137 glVertex3f(.5, -.5, -30.0);
138
139 glVertex3f(-.5, -.5, -30.0);
140 glVertex3f(.5, -.5, -30.0);
141 glVertex3f(0, 0, -30.0);
142
143
144 glColor3f(0,1,0);
145 glVertex3f(1, 1, -30.0);
146 glVertex3f(0, 1, -30.0);
147 glVertex3f(.5, .5, -30.0);
148
149 glColor3f(1,1,1);
150 glVertex3f(0, 1, -30.0);
151 glVertex3f(-1, 1, -30.0);
152 glVertex3f(-.5, .5, -30.0);
153
154 glVertex3f(.5, .5, -30.0);
155 glVertex3f(-.5, .5, -30.0);
156 glVertex3f( 0, 0, -30.0);
157
158 glEnd();
159
160
Keith Whitwell6bfcffa2009-04-20 17:30:53 +0100161 glViewport(0, 0, win_width, win_height);
Keith Whitwellc691f962009-04-20 15:50:44 +0100162
163 glBegin(GL_LINES);
164 glColor3f(.5,.5,0);
165 for (i = -10; i < 10; i++) {
166 float f = i / 10.0;
167
168 if (i == 0)
169 continue;
170
171 glVertex3f(-1, f, -30.0);
172 glVertex3f(1, f, -30.0);
173
174 glVertex3f(f, -1, -30.0);
175 glVertex3f(f, 1, -30.0);
176 }
177 glEnd();
178
179
180
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +0100181 glFlush();
182
183 if (doubleBuffer) {
184 glutSwapBuffers();
185 }
186}
187
188static GLenum Args(int argc, char **argv)
189{
190 GLint i;
191
Keith Whitwellc691f962009-04-20 15:50:44 +0100192 if (getenv("VPX"))
193 tx = atof(getenv("VPX"));
194
195 if (getenv("VPY"))
196 ty = atof(getenv("VPY"));
197
198
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +0100199 for (i = 1; i < argc; i++) {
200 if (strcmp(argv[i], "-sb") == 0) {
201 doubleBuffer = GL_FALSE;
202 } else if (strcmp(argv[i], "-db") == 0) {
203 doubleBuffer = GL_TRUE;
204 } else {
205 fprintf(stderr, "%s (Bad option).\n", argv[i]);
206 return GL_FALSE;
207 }
208 }
209 return GL_TRUE;
210}
211
Keith Whitwellc691f962009-04-20 15:50:44 +0100212
213static void
214special(int k, int x, int y)
215{
216 switch (k) {
217 case GLUT_KEY_UP:
218 ty += 1.0;
219 break;
220 case GLUT_KEY_DOWN:
221 ty -= 1.0;
222 break;
223 case GLUT_KEY_LEFT:
224 tx -= 1.0;
225 break;
226 case GLUT_KEY_RIGHT:
227 tx += 1.0;
228 break;
229 default:
Keith Whitwell6bfcffa2009-04-20 17:30:53 +0100230 break;
Keith Whitwellc691f962009-04-20 15:50:44 +0100231 }
232 glutPostRedisplay();
233}
234
235
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +0100236int main(int argc, char **argv)
237{
238 GLenum type;
239
240 glutInit(&argc, argv);
241
242 if (Args(argc, argv) == GL_FALSE) {
243 exit(1);
244 }
245
246 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
247
248 type = GLUT_RGB | GLUT_ALPHA;
249 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
250 glutInitDisplayMode(type);
251
252 win = glutCreateWindow(*argv);
253 if (!win) {
254 exit(1);
255 }
256
257 Init();
258
259 glutReshapeFunc(Reshape);
Keith Whitwellc691f962009-04-20 15:50:44 +0100260 glutKeyboardFunc(Key);
261 glutSpecialFunc(special);
Jakob Bornecrantzbd2f9212009-02-21 11:58:48 +0100262 glutDisplayFunc(Draw);
263 glutMainLoop();
264 return 0;
265}