blob: ec431c16f008003900c7c71e95300d8abcbf7a9b [file] [log] [blame]
Brian Paul355da232001-03-23 22:46:26 +00001/*
2 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22/*
23 * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
24 * Port by Brian Paul 23 March 2001
25 *
Brian Paulad802332003-04-09 21:47:19 +000026 * Command line options:
Brian Paul50253ea2003-09-08 15:06:23 +000027 * -info print GL implementation information
Brian Paul20831312004-10-26 14:36:32 +000028 * -stereo use stereo enabled GLX visual
Brian Paul50253ea2003-09-08 15:06:23 +000029 *
Brian Paul355da232001-03-23 22:46:26 +000030 */
31
32
33#include <math.h>
34#include <stdlib.h>
35#include <stdio.h>
36#include <string.h>
37#include <X11/Xlib.h>
38#include <X11/keysym.h>
39#include <GL/gl.h>
40#include <GL/glx.h>
41
Brian Paul785774d2003-05-30 15:30:16 +000042
Brian Paul355da232001-03-23 22:46:26 +000043#define BENCHMARK
44
45#ifdef BENCHMARK
46
47/* XXX this probably isn't very portable */
48
49#include <sys/time.h>
50#include <unistd.h>
51
52/* return current time (in seconds) */
Brian Paul612bf1f2005-01-09 18:00:49 +000053static double
Brian Paul355da232001-03-23 22:46:26 +000054current_time(void)
55{
56 struct timeval tv;
Jouk Jansenf72a3da2002-10-08 08:38:26 +000057#ifdef __VMS
58 (void) gettimeofday(&tv, NULL );
59#else
Brian Paul355da232001-03-23 22:46:26 +000060 struct timezone tz;
61 (void) gettimeofday(&tv, &tz);
Jouk Jansenf72a3da2002-10-08 08:38:26 +000062#endif
Brian Paul612bf1f2005-01-09 18:00:49 +000063 return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
Brian Paul355da232001-03-23 22:46:26 +000064}
65
66#else /*BENCHMARK*/
67
68/* dummy */
Brian Paul612bf1f2005-01-09 18:00:49 +000069static double
Brian Paul355da232001-03-23 22:46:26 +000070current_time(void)
71{
Brian Paul612bf1f2005-01-09 18:00:49 +000072 /* update this function for other platforms! */
73 static double t = 0.0;
74 static int warn = 1;
75 if (warn) {
76 fprintf(stderr, "Warning: current_time() not implemented!!\n");
77 warn = 0;
78 }
79 return t += 1.0;
Brian Paul355da232001-03-23 22:46:26 +000080}
81
82#endif /*BENCHMARK*/
83
84
85
86#ifndef M_PI
87#define M_PI 3.14159265
88#endif
89
90
91static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
92static GLint gear1, gear2, gear3;
93static GLfloat angle = 0.0;
94
Keith Whitwell16db1572004-12-20 14:48:19 +000095static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
Brian Paul20831312004-10-26 14:36:32 +000096static GLboolean stereo = GL_FALSE; /* Enable stereo. */
97static GLfloat eyesep = 5.0; /* Eye separation. */
98static GLfloat fix_point = 40.0; /* Fixation point distance. */
99static GLfloat left, right, asp; /* Stereo frustum params. */
100
Brian Paul785774d2003-05-30 15:30:16 +0000101
Brian Paul355da232001-03-23 22:46:26 +0000102/*
103 *
104 * Draw a gear wheel. You'll probably want to call this function when
105 * building a display list since we do a lot of trig here.
106 *
107 * Input: inner_radius - radius of hole at center
108 * outer_radius - radius at center of teeth
109 * width - width of gear
110 * teeth - number of teeth
111 * tooth_depth - depth of tooth
112 */
113static void
114gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
115 GLint teeth, GLfloat tooth_depth)
116{
117 GLint i;
118 GLfloat r0, r1, r2;
119 GLfloat angle, da;
120 GLfloat u, v, len;
121
122 r0 = inner_radius;
123 r1 = outer_radius - tooth_depth / 2.0;
124 r2 = outer_radius + tooth_depth / 2.0;
125
126 da = 2.0 * M_PI / teeth / 4.0;
127
128 glShadeModel(GL_FLAT);
129
130 glNormal3f(0.0, 0.0, 1.0);
131
132 /* draw front face */
133 glBegin(GL_QUAD_STRIP);
134 for (i = 0; i <= teeth; i++) {
135 angle = i * 2.0 * M_PI / teeth;
136 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
137 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
138 if (i < teeth) {
139 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
140 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
141 width * 0.5);
142 }
143 }
144 glEnd();
145
146 /* draw front sides of teeth */
147 glBegin(GL_QUADS);
148 da = 2.0 * M_PI / teeth / 4.0;
149 for (i = 0; i < teeth; i++) {
150 angle = i * 2.0 * M_PI / teeth;
151
152 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
153 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
154 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
155 width * 0.5);
156 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
157 width * 0.5);
158 }
159 glEnd();
160
161 glNormal3f(0.0, 0.0, -1.0);
162
163 /* draw back face */
164 glBegin(GL_QUAD_STRIP);
165 for (i = 0; i <= teeth; i++) {
166 angle = i * 2.0 * M_PI / teeth;
167 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
168 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
169 if (i < teeth) {
170 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
171 -width * 0.5);
172 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
173 }
174 }
175 glEnd();
176
177 /* draw back sides of teeth */
178 glBegin(GL_QUADS);
179 da = 2.0 * M_PI / teeth / 4.0;
180 for (i = 0; i < teeth; i++) {
181 angle = i * 2.0 * M_PI / teeth;
182
183 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
184 -width * 0.5);
185 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
186 -width * 0.5);
187 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
188 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
189 }
190 glEnd();
191
192 /* draw outward faces of teeth */
193 glBegin(GL_QUAD_STRIP);
194 for (i = 0; i < teeth; i++) {
195 angle = i * 2.0 * M_PI / teeth;
196
197 glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
198 glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
199 u = r2 * cos(angle + da) - r1 * cos(angle);
200 v = r2 * sin(angle + da) - r1 * sin(angle);
201 len = sqrt(u * u + v * v);
202 u /= len;
203 v /= len;
204 glNormal3f(v, -u, 0.0);
205 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
206 glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
207 glNormal3f(cos(angle), sin(angle), 0.0);
208 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
209 width * 0.5);
210 glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
211 -width * 0.5);
212 u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
213 v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
214 glNormal3f(v, -u, 0.0);
215 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
216 width * 0.5);
217 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
218 -width * 0.5);
219 glNormal3f(cos(angle), sin(angle), 0.0);
220 }
221
222 glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
223 glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
224
225 glEnd();
226
227 glShadeModel(GL_SMOOTH);
228
229 /* draw inside radius cylinder */
230 glBegin(GL_QUAD_STRIP);
231 for (i = 0; i <= teeth; i++) {
232 angle = i * 2.0 * M_PI / teeth;
233 glNormal3f(-cos(angle), -sin(angle), 0.0);
234 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
235 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
236 }
237 glEnd();
238}
239
240
241static void
Brian Paul20831312004-10-26 14:36:32 +0000242do_draw(void)
Brian Paul355da232001-03-23 22:46:26 +0000243{
Brian Paul50253ea2003-09-08 15:06:23 +0000244 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Brian Paul355da232001-03-23 22:46:26 +0000245
246 glPushMatrix();
247 glRotatef(view_rotx, 1.0, 0.0, 0.0);
248 glRotatef(view_roty, 0.0, 1.0, 0.0);
249 glRotatef(view_rotz, 0.0, 0.0, 1.0);
250
251 glPushMatrix();
252 glTranslatef(-3.0, -2.0, 0.0);
253 glRotatef(angle, 0.0, 0.0, 1.0);
254 glCallList(gear1);
255 glPopMatrix();
256
257 glPushMatrix();
258 glTranslatef(3.1, -2.0, 0.0);
259 glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
260 glCallList(gear2);
261 glPopMatrix();
262
263 glPushMatrix();
264 glTranslatef(-3.1, 4.2, 0.0);
265 glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
266 glCallList(gear3);
267 glPopMatrix();
268
269 glPopMatrix();
270}
271
Brian Paul20831312004-10-26 14:36:32 +0000272static void
273draw(void)
274{
275 if (stereo) {
276 /* First left eye. */
277 glDrawBuffer(GL_BACK_LEFT);
278
279 glMatrixMode(GL_PROJECTION);
280 glLoadIdentity();
281 glFrustum(left, right, -asp, asp, 5.0, 60.0);
282
283 glMatrixMode(GL_MODELVIEW);
284
285 glPushMatrix();
286 glTranslated(+0.5 * eyesep, 0.0, 0.0);
287 do_draw();
288 glPopMatrix();
289
290 /* Then right eye. */
291 glDrawBuffer(GL_BACK_RIGHT);
292
293 glMatrixMode(GL_PROJECTION);
294 glLoadIdentity();
295 glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
296
297 glMatrixMode(GL_MODELVIEW);
298
299 glPushMatrix();
300 glTranslated(-0.5 * eyesep, 0.0, 0.0);
301 do_draw();
302 glPopMatrix();
303 } else
304 do_draw();
305}
306
Brian Paul355da232001-03-23 22:46:26 +0000307
308/* new window size or exposure */
309static void
310reshape(int width, int height)
311{
Brian Paul355da232001-03-23 22:46:26 +0000312 glViewport(0, 0, (GLint) width, (GLint) height);
Brian Paul20831312004-10-26 14:36:32 +0000313
314 if (stereo) {
315 GLfloat w;
316
317 asp = (GLfloat) height / (GLfloat) width;
318 w = fix_point * (1.0 / 5.0);
319
320 left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
321 right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
322 } else {
323 GLfloat h = (GLfloat) height / (GLfloat) width;
324
325 glMatrixMode(GL_PROJECTION);
326 glLoadIdentity();
327 glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
328 }
329
Brian Paul355da232001-03-23 22:46:26 +0000330 glMatrixMode(GL_MODELVIEW);
331 glLoadIdentity();
332 glTranslatef(0.0, 0.0, -40.0);
333}
Brian Paul20831312004-10-26 14:36:32 +0000334
Brian Paul355da232001-03-23 22:46:26 +0000335
336
337static void
338init(void)
339{
340 static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
341 static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
342 static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
343 static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
344
345 glLightfv(GL_LIGHT0, GL_POSITION, pos);
346 glEnable(GL_CULL_FACE);
347 glEnable(GL_LIGHTING);
348 glEnable(GL_LIGHT0);
349 glEnable(GL_DEPTH_TEST);
350
351 /* make the gears */
352 gear1 = glGenLists(1);
353 glNewList(gear1, GL_COMPILE);
354 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
355 gear(1.0, 4.0, 1.0, 20, 0.7);
356 glEndList();
357
358 gear2 = glGenLists(1);
359 glNewList(gear2, GL_COMPILE);
360 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
361 gear(0.5, 2.0, 2.0, 10, 0.7);
362 glEndList();
363
364 gear3 = glGenLists(1);
365 glNewList(gear3, GL_COMPILE);
366 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
367 gear(1.3, 2.0, 0.5, 10, 0.7);
368 glEndList();
369
370 glEnable(GL_NORMALIZE);
371}
372
373
374/*
375 * Create an RGB, double-buffered window.
376 * Return the window and context handles.
377 */
378static void
379make_window( Display *dpy, const char *name,
380 int x, int y, int width, int height,
381 Window *winRet, GLXContext *ctxRet)
382{
Brian Paul20831312004-10-26 14:36:32 +0000383 int attribs[] = { GLX_RGBA,
384 GLX_RED_SIZE, 1,
385 GLX_GREEN_SIZE, 1,
386 GLX_BLUE_SIZE, 1,
387 GLX_DOUBLEBUFFER,
388 GLX_DEPTH_SIZE, 1,
389 None };
390 int stereoAttribs[] = { GLX_RGBA,
391 GLX_RED_SIZE, 1,
392 GLX_GREEN_SIZE, 1,
393 GLX_BLUE_SIZE, 1,
394 GLX_DOUBLEBUFFER,
395 GLX_DEPTH_SIZE, 1,
396 GLX_STEREO,
397 None };
Brian Paul355da232001-03-23 22:46:26 +0000398 int scrnum;
399 XSetWindowAttributes attr;
400 unsigned long mask;
401 Window root;
402 Window win;
403 GLXContext ctx;
404 XVisualInfo *visinfo;
405
406 scrnum = DefaultScreen( dpy );
407 root = RootWindow( dpy, scrnum );
408
Keith Whitwell16db1572004-12-20 14:48:19 +0000409 if (fullscreen) {
410 x = 0; y = 0;
411 width = DisplayWidth( dpy, scrnum );
412 height = DisplayHeight( dpy, scrnum );
413 }
414
Brian Paul20831312004-10-26 14:36:32 +0000415 if (stereo)
416 visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
417 else
418 visinfo = glXChooseVisual( dpy, scrnum, attribs );
Brian Paul355da232001-03-23 22:46:26 +0000419 if (!visinfo) {
Brian Paul20831312004-10-26 14:36:32 +0000420 if (stereo) {
421 printf("Error: couldn't get an RGB, "
422 "Double-buffered, Stereo visual\n");
423 } else
424 printf("Error: couldn't get an RGB, Double-buffered visual\n");
Brian Paul355da232001-03-23 22:46:26 +0000425 exit(1);
426 }
427
428 /* window attributes */
429 attr.background_pixel = 0;
430 attr.border_pixel = 0;
431 attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
432 attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
Keith Whitwell16db1572004-12-20 14:48:19 +0000433 attr.override_redirect = fullscreen;
434 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
Brian Paul355da232001-03-23 22:46:26 +0000435
Briane45b4032007-08-07 22:02:27 +0100436 win = XCreateWindow( dpy, root, x, y, width, height,
Brian Paul355da232001-03-23 22:46:26 +0000437 0, visinfo->depth, InputOutput,
438 visinfo->visual, mask, &attr );
439
440 /* set hints and properties */
441 {
442 XSizeHints sizehints;
443 sizehints.x = x;
444 sizehints.y = y;
445 sizehints.width = width;
446 sizehints.height = height;
447 sizehints.flags = USSize | USPosition;
448 XSetNormalHints(dpy, win, &sizehints);
449 XSetStandardProperties(dpy, win, name, name,
450 None, (char **)NULL, 0, &sizehints);
451 }
452
453 ctx = glXCreateContext( dpy, visinfo, NULL, True );
454 if (!ctx) {
455 printf("Error: glXCreateContext failed\n");
456 exit(1);
457 }
458
459 XFree(visinfo);
460
461 *winRet = win;
462 *ctxRet = ctx;
463}
464
465
466static void
467event_loop(Display *dpy, Window win)
468{
469 while (1) {
470 while (XPending(dpy) > 0) {
471 XEvent event;
472 XNextEvent(dpy, &event);
473 switch (event.type) {
474 case Expose:
475 /* we'll redraw below */
476 break;
477 case ConfigureNotify:
478 reshape(event.xconfigure.width, event.xconfigure.height);
479 break;
480 case KeyPress:
481 {
482 char buffer[10];
483 int r, code;
484 code = XLookupKeysym(&event.xkey, 0);
485 if (code == XK_Left) {
486 view_roty += 5.0;
487 }
488 else if (code == XK_Right) {
489 view_roty -= 5.0;
490 }
491 else if (code == XK_Up) {
492 view_rotx += 5.0;
493 }
494 else if (code == XK_Down) {
495 view_rotx -= 5.0;
496 }
497 else {
498 r = XLookupString(&event.xkey, buffer, sizeof(buffer),
499 NULL, NULL);
500 if (buffer[0] == 27) {
501 /* escape */
502 return;
503 }
504 }
505 }
506 }
507 }
508
Brian Paul355da232001-03-23 22:46:26 +0000509 {
Brian Paul355da232001-03-23 22:46:26 +0000510 static int frames = 0;
Brian Paul612bf1f2005-01-09 18:00:49 +0000511 static double tRot0 = -1.0, tRate0 = -1.0;
512 double dt, t = current_time();
513 if (tRot0 < 0.0)
514 tRot0 = t;
515 dt = t - tRot0;
516 tRot0 = t;
Brian Paul355da232001-03-23 22:46:26 +0000517
Brian Paul612bf1f2005-01-09 18:00:49 +0000518 /* advance rotation for next frame */
519 angle += 70.0 * dt; /* 70 degrees per second */
520 if (angle > 3600.0)
521 angle -= 3600.0;
522
523 draw();
524 glXSwapBuffers(dpy, win);
Brian Paul355da232001-03-23 22:46:26 +0000525
526 frames++;
527
Brian Paul612bf1f2005-01-09 18:00:49 +0000528 if (tRate0 < 0.0)
529 tRate0 = t;
530 if (t - tRate0 >= 5.0) {
531 GLfloat seconds = t - tRate0;
Brian Paul355da232001-03-23 22:46:26 +0000532 GLfloat fps = frames / seconds;
Brian Paul50253ea2003-09-08 15:06:23 +0000533 printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
534 fps);
Brian Paul612bf1f2005-01-09 18:00:49 +0000535 tRate0 = t;
Brian Paul355da232001-03-23 22:46:26 +0000536 frames = 0;
537 }
538 }
539 }
540}
541
542
Brian Paulc8ea1112006-05-15 15:14:37 +0000543static void
544usage(void)
545{
546 printf("Usage:\n");
547 printf(" -display <displayname> set the display to run on\n");
548 printf(" -stereo run in stereo mode\n");
549 printf(" -fullscreen run in fullscreen mode\n");
550 printf(" -info display OpenGL renderer info\n");
Ingo Molnar4a8ad162007-08-07 09:53:48 +0200551 printf(" -winwidth <width> window width (default: 300)\n");
552 printf(" -winheight <height> window height (default: 300)\n");
Brian Paulc8ea1112006-05-15 15:14:37 +0000553}
554
555
Brian Paul355da232001-03-23 22:46:26 +0000556int
557main(int argc, char *argv[])
558{
Briane45b4032007-08-07 22:02:27 +0100559 unsigned int winWidth = 300, winHeight = 300;
560 int x = 0, y = 0;
Brian Paul355da232001-03-23 22:46:26 +0000561 Display *dpy;
562 Window win;
563 GLXContext ctx;
Brian Paul20831312004-10-26 14:36:32 +0000564 char *dpyName = NULL;
Brian Paul355da232001-03-23 22:46:26 +0000565 GLboolean printInfo = GL_FALSE;
566 int i;
567
568 for (i = 1; i < argc; i++) {
Brian Paul50253ea2003-09-08 15:06:23 +0000569 if (strcmp(argv[i], "-display") == 0) {
Brian Paul355da232001-03-23 22:46:26 +0000570 dpyName = argv[i+1];
571 i++;
572 }
573 else if (strcmp(argv[i], "-info") == 0) {
574 printInfo = GL_TRUE;
575 }
Brian Paul20831312004-10-26 14:36:32 +0000576 else if (strcmp(argv[i], "-stereo") == 0) {
577 stereo = GL_TRUE;
578 }
Keith Whitwell16db1572004-12-20 14:48:19 +0000579 else if (strcmp(argv[i], "-fullscreen") == 0) {
580 fullscreen = GL_TRUE;
581 }
Briane45b4032007-08-07 22:02:27 +0100582 else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
583 XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
Ingo Molnar4a8ad162007-08-07 09:53:48 +0200584 i++;
585 }
Brian Paulc8ea1112006-05-15 15:14:37 +0000586 else {
587 usage();
588 return -1;
589 }
Brian Paul355da232001-03-23 22:46:26 +0000590 }
591
592 dpy = XOpenDisplay(dpyName);
593 if (!dpy) {
Brian Paul20831312004-10-26 14:36:32 +0000594 printf("Error: couldn't open display %s\n",
595 dpyName ? dpyName : getenv("DISPLAY"));
Brian Paul355da232001-03-23 22:46:26 +0000596 return -1;
597 }
598
Briane45b4032007-08-07 22:02:27 +0100599 make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
Brian Paul355da232001-03-23 22:46:26 +0000600 XMapWindow(dpy, win);
601 glXMakeCurrent(dpy, win, ctx);
602
603 if (printInfo) {
604 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
605 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
606 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
607 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
Brian Paul355da232001-03-23 22:46:26 +0000608 }
609
610 init();
611
Brian Paul4c6319d2006-05-17 22:44:18 +0000612 /* Set initial projection/viewing transformation.
613 * We can't be sure we'll get a ConfigureNotify event when the window
614 * first appears.
615 */
616 reshape(winWidth, winHeight);
617
Brian Paul355da232001-03-23 22:46:26 +0000618 event_loop(dpy, win);
619
Brian Paule78a3c42005-08-09 15:14:51 +0000620 glDeleteLists(gear1, 1);
621 glDeleteLists(gear2, 1);
622 glDeleteLists(gear3, 1);
Brian Paul355da232001-03-23 22:46:26 +0000623 glXDestroyContext(dpy, ctx);
624 XDestroyWindow(dpy, win);
625 XCloseDisplay(dpy);
626
627 return 0;
628}