Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glxgears.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  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. * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
  23. * Port by Brian Paul 23 March 2001
  24. *
  25. * Command line options:
  26. * -info print GL implementation information
  27. * -stereo use stereo enabled GLX visual
  28. *
  29. */
  30. #include <math.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <X11/Xlib.h>
  35. #include <X11/keysym.h>
  36. #include <GL/gl.h>
  37. #include <GL/glx.h>
  38. #define BENCHMARK
  39. #ifdef BENCHMARK
  40. /* XXX this probably isn't very portable */
  41. #include <sys/time.h>
  42. #include <unistd.h>
  43. /* return current time (in seconds) */
  44. static double
  45. current_time(void)
  46. {
  47. struct timeval tv;
  48. #ifdef __VMS
  49. (void) gettimeofday(&tv, NULL );
  50. #else
  51. struct timezone tz;
  52. (void) gettimeofday(&tv, &tz);
  53. #endif
  54. return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
  55. }
  56. #else /*BENCHMARK*/
  57. /* dummy */
  58. static double
  59. current_time(void)
  60. {
  61. /* update this function for other platforms! */
  62. static double t = 0.0;
  63. static int warn = 1;
  64. if (warn) {
  65. fprintf(stderr, "Warning: current_time() not implemented!!\n");
  66. warn = 0;
  67. }
  68. return t += 1.0;
  69. }
  70. #endif /*BENCHMARK*/
  71. #ifndef M_PI
  72. #define M_PI 3.14159265
  73. #endif
  74. /** Event handler results: */
  75. #define NOP 0
  76. #define EXIT 1
  77. #define DRAW 2
  78. static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
  79. static GLint gear1, gear2, gear3;
  80. static GLfloat angle = 0.0;
  81. static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
  82. static GLboolean stereo = GL_FALSE; /* Enable stereo. */
  83. static GLboolean animate = GL_TRUE; /* Animation */
  84. static GLfloat eyesep = 5.0; /* Eye separation. */
  85. static GLfloat fix_point = 40.0; /* Fixation point distance. */
  86. static GLfloat left, right, asp; /* Stereo frustum params. */
  87. /*
  88. *
  89. * Draw a gear wheel. You'll probably want to call this function when
  90. * building a display list since we do a lot of trig here.
  91. *
  92. * Input: inner_radius - radius of hole at center
  93. * outer_radius - radius at center of teeth
  94. * width - width of gear
  95. * teeth - number of teeth
  96. * tooth_depth - depth of tooth
  97. */
  98. static void
  99. gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
  100. GLint teeth, GLfloat tooth_depth)
  101. {
  102. GLint i;
  103. GLfloat r0, r1, r2;
  104. GLfloat angle, da;
  105. GLfloat u, v, len;
  106. r0 = inner_radius;
  107. r1 = outer_radius - tooth_depth / 2.0;
  108. r2 = outer_radius + tooth_depth / 2.0;
  109. da = 2.0 * M_PI / teeth / 4.0;
  110. glShadeModel(GL_FLAT);
  111. glNormal3f(0.0, 0.0, 1.0);
  112. /* draw front face */
  113. glBegin(GL_QUAD_STRIP);
  114. for (i = 0; i <= teeth; i++) {
  115. angle = i * 2.0 * M_PI / teeth;
  116. glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  117. glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  118. if (i < teeth) {
  119. glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  120. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  121. width * 0.5);
  122. }
  123. }
  124. glEnd();
  125. /* draw front sides of teeth */
  126. glBegin(GL_QUADS);
  127. da = 2.0 * M_PI / teeth / 4.0;
  128. for (i = 0; i < teeth; i++) {
  129. angle = i * 2.0 * M_PI / teeth;
  130. glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  131. glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  132. glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  133. width * 0.5);
  134. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  135. width * 0.5);
  136. }
  137. glEnd();
  138. glNormal3f(0.0, 0.0, -1.0);
  139. /* draw back face */
  140. glBegin(GL_QUAD_STRIP);
  141. for (i = 0; i <= teeth; i++) {
  142. angle = i * 2.0 * M_PI / teeth;
  143. glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  144. glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  145. if (i < teeth) {
  146. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  147. -width * 0.5);
  148. glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  149. }
  150. }
  151. glEnd();
  152. /* draw back sides of teeth */
  153. glBegin(GL_QUADS);
  154. da = 2.0 * M_PI / teeth / 4.0;
  155. for (i = 0; i < teeth; i++) {
  156. angle = i * 2.0 * M_PI / teeth;
  157. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  158. -width * 0.5);
  159. glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  160. -width * 0.5);
  161. glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  162. glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  163. }
  164. glEnd();
  165. /* draw outward faces of teeth */
  166. glBegin(GL_QUAD_STRIP);
  167. for (i = 0; i < teeth; i++) {
  168. angle = i * 2.0 * M_PI / teeth;
  169. glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
  170. glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
  171. u = r2 * cos(angle + da) - r1 * cos(angle);
  172. v = r2 * sin(angle + da) - r1 * sin(angle);
  173. len = sqrt(u * u + v * v);
  174. u /= len;
  175. v /= len;
  176. glNormal3f(v, -u, 0.0);
  177. glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
  178. glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
  179. glNormal3f(cos(angle), sin(angle), 0.0);
  180. glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  181. width * 0.5);
  182. glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
  183. -width * 0.5);
  184. u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
  185. v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
  186. glNormal3f(v, -u, 0.0);
  187. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  188. width * 0.5);
  189. glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
  190. -width * 0.5);
  191. glNormal3f(cos(angle), sin(angle), 0.0);
  192. }
  193. glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
  194. glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
  195. glEnd();
  196. glShadeModel(GL_SMOOTH);
  197. /* draw inside radius cylinder */
  198. glBegin(GL_QUAD_STRIP);
  199. for (i = 0; i <= teeth; i++) {
  200. angle = i * 2.0 * M_PI / teeth;
  201. glNormal3f(-cos(angle), -sin(angle), 0.0);
  202. glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
  203. glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
  204. }
  205. glEnd();
  206. }
  207. static void
  208. draw(void)
  209. {
  210. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  211. glPushMatrix();
  212. glRotatef(view_rotx, 1.0, 0.0, 0.0);
  213. glRotatef(view_roty, 0.0, 1.0, 0.0);
  214. glRotatef(view_rotz, 0.0, 0.0, 1.0);
  215. glPushMatrix();
  216. glTranslatef(-3.0, -2.0, 0.0);
  217. glRotatef(angle, 0.0, 0.0, 1.0);
  218. glCallList(gear1);
  219. glPopMatrix();
  220. glPushMatrix();
  221. glTranslatef(3.1, -2.0, 0.0);
  222. glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
  223. glCallList(gear2);
  224. glPopMatrix();
  225. glPushMatrix();
  226. glTranslatef(-3.1, 4.2, 0.0);
  227. glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
  228. glCallList(gear3);
  229. glPopMatrix();
  230. glPopMatrix();
  231. }
  232. static void
  233. draw_gears(void)
  234. {
  235. if (stereo) {
  236. /* First left eye. */
  237. glDrawBuffer(GL_BACK_LEFT);
  238. glMatrixMode(GL_PROJECTION);
  239. glLoadIdentity();
  240. glFrustum(left, right, -asp, asp, 5.0, 60.0);
  241. glMatrixMode(GL_MODELVIEW);
  242. glPushMatrix();
  243. glTranslated(+0.5 * eyesep, 0.0, 0.0);
  244. draw();
  245. glPopMatrix();
  246. /* Then right eye. */
  247. glDrawBuffer(GL_BACK_RIGHT);
  248. glMatrixMode(GL_PROJECTION);
  249. glLoadIdentity();
  250. glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
  251. glMatrixMode(GL_MODELVIEW);
  252. glPushMatrix();
  253. glTranslated(-0.5 * eyesep, 0.0, 0.0);
  254. draw();
  255. glPopMatrix();
  256. }
  257. else {
  258. draw();
  259. }
  260. }
  261. /** Draw single frame, do SwapBuffers, compute FPS */
  262. static void
  263. draw_frame(Display *dpy, Window win)
  264. {
  265. static int frames = 0;
  266. static double tRot0 = -1.0, tRate0 = -1.0;
  267. double dt, t = current_time();
  268. if (tRot0 < 0.0)
  269. tRot0 = t;
  270. dt = t - tRot0;
  271. tRot0 = t;
  272. if (animate) {
  273. /* advance rotation for next frame */
  274. angle += 70.0 * dt; /* 70 degrees per second */
  275. if (angle > 3600.0)
  276. angle -= 3600.0;
  277. }
  278. draw_gears();
  279. glXSwapBuffers(dpy, win);
  280. frames++;
  281. if (tRate0 < 0.0)
  282. tRate0 = t;
  283. if (t - tRate0 >= 5.0) {
  284. GLfloat seconds = t - tRate0;
  285. GLfloat fps = frames / seconds;
  286. printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
  287. fps);
  288. tRate0 = t;
  289. frames = 0;
  290. }
  291. }
  292. /* new window size or exposure */
  293. static void
  294. reshape(int width, int height)
  295. {
  296. glViewport(0, 0, (GLint) width, (GLint) height);
  297. if (stereo) {
  298. GLfloat w;
  299. asp = (GLfloat) height / (GLfloat) width;
  300. w = fix_point * (1.0 / 5.0);
  301. left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
  302. right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
  303. }
  304. else {
  305. GLfloat h = (GLfloat) height / (GLfloat) width;
  306. glMatrixMode(GL_PROJECTION);
  307. glLoadIdentity();
  308. glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
  309. }
  310. glMatrixMode(GL_MODELVIEW);
  311. glLoadIdentity();
  312. glTranslatef(0.0, 0.0, -40.0);
  313. }
  314. static void
  315. init(void)
  316. {
  317. static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
  318. static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
  319. static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
  320. static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
  321. glLightfv(GL_LIGHT0, GL_POSITION, pos);
  322. glEnable(GL_CULL_FACE);
  323. glEnable(GL_LIGHTING);
  324. glEnable(GL_LIGHT0);
  325. glEnable(GL_DEPTH_TEST);
  326. /* make the gears */
  327. gear1 = glGenLists(1);
  328. glNewList(gear1, GL_COMPILE);
  329. glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
  330. gear(1.0, 4.0, 1.0, 20, 0.7);
  331. glEndList();
  332. gear2 = glGenLists(1);
  333. glNewList(gear2, GL_COMPILE);
  334. glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
  335. gear(0.5, 2.0, 2.0, 10, 0.7);
  336. glEndList();
  337. gear3 = glGenLists(1);
  338. glNewList(gear3, GL_COMPILE);
  339. glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
  340. gear(1.3, 2.0, 0.5, 10, 0.7);
  341. glEndList();
  342. glEnable(GL_NORMALIZE);
  343. }
  344. /*
  345. * Create an RGB, double-buffered window.
  346. * Return the window and context handles.
  347. */
  348. static void
  349. make_window( Display *dpy, const char *name,
  350. int x, int y, int width, int height,
  351. Window *winRet, GLXContext *ctxRet)
  352. {
  353. int attribs[] = { GLX_RGBA,
  354. GLX_RED_SIZE, 1,
  355. GLX_GREEN_SIZE, 1,
  356. GLX_BLUE_SIZE, 1,
  357. GLX_DOUBLEBUFFER,
  358. GLX_DEPTH_SIZE, 1,
  359. None };
  360. int stereoAttribs[] = { GLX_RGBA,
  361. GLX_RED_SIZE, 1,
  362. GLX_GREEN_SIZE, 1,
  363. GLX_BLUE_SIZE, 1,
  364. GLX_DOUBLEBUFFER,
  365. GLX_DEPTH_SIZE, 1,
  366. GLX_STEREO,
  367. None };
  368. int scrnum;
  369. XSetWindowAttributes attr;
  370. unsigned long mask;
  371. Window root;
  372. Window win;
  373. GLXContext ctx;
  374. XVisualInfo *visinfo;
  375. scrnum = DefaultScreen( dpy );
  376. root = RootWindow( dpy, scrnum );
  377. if (fullscreen) {
  378. x = 0; y = 0;
  379. width = DisplayWidth( dpy, scrnum );
  380. height = DisplayHeight( dpy, scrnum );
  381. }
  382. if (stereo)
  383. visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
  384. else
  385. visinfo = glXChooseVisual( dpy, scrnum, attribs );
  386. if (!visinfo) {
  387. if (stereo) {
  388. printf("Error: couldn't get an RGB, "
  389. "Double-buffered, Stereo visual\n");
  390. } else
  391. printf("Error: couldn't get an RGB, Double-buffered visual\n");
  392. exit(1);
  393. }
  394. /* window attributes */
  395. attr.background_pixel = 0;
  396. attr.border_pixel = 0;
  397. attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
  398. attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  399. /* XXX this is a bad way to get a borderless window! */
  400. attr.override_redirect = fullscreen;
  401. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;
  402. win = XCreateWindow( dpy, root, x, y, width, height,
  403. 0, visinfo->depth, InputOutput,
  404. visinfo->visual, mask, &attr );
  405. /* set hints and properties */
  406. {
  407. XSizeHints sizehints;
  408. sizehints.x = x;
  409. sizehints.y = y;
  410. sizehints.width = width;
  411. sizehints.height = height;
  412. sizehints.flags = USSize | USPosition;
  413. XSetNormalHints(dpy, win, &sizehints);
  414. XSetStandardProperties(dpy, win, name, name,
  415. None, (char **)NULL, 0, &sizehints);
  416. }
  417. ctx = glXCreateContext( dpy, visinfo, NULL, True );
  418. if (!ctx) {
  419. printf("Error: glXCreateContext failed\n");
  420. exit(1);
  421. }
  422. XFree(visinfo);
  423. *winRet = win;
  424. *ctxRet = ctx;
  425. }
  426. /**
  427. * Handle one X event.
  428. * \return NOP, EXIT or DRAW
  429. */
  430. static int
  431. handle_event(Display *dpy, Window win, XEvent *event)
  432. {
  433. switch (event->type) {
  434. case Expose:
  435. return DRAW;
  436. case ConfigureNotify:
  437. reshape(event->xconfigure.width, event->xconfigure.height);
  438. break;
  439. case KeyPress:
  440. {
  441. char buffer[10];
  442. int r, code;
  443. code = XLookupKeysym(&event->xkey, 0);
  444. if (code == XK_Left) {
  445. view_roty += 5.0;
  446. }
  447. else if (code == XK_Right) {
  448. view_roty -= 5.0;
  449. }
  450. else if (code == XK_Up) {
  451. view_rotx += 5.0;
  452. }
  453. else if (code == XK_Down) {
  454. view_rotx -= 5.0;
  455. }
  456. else {
  457. r = XLookupString(&event->xkey, buffer, sizeof(buffer),
  458. NULL, NULL);
  459. if (buffer[0] == 27) {
  460. /* escape */
  461. return EXIT;
  462. }
  463. else if (buffer[0] == 'a' || buffer[0] == 'A') {
  464. animate = !animate;
  465. }
  466. }
  467. return DRAW;
  468. }
  469. }
  470. return NOP;
  471. }
  472. static void
  473. event_loop(Display *dpy, Window win)
  474. {
  475. while (1) {
  476. int op;
  477. while (!animate || XPending(dpy) > 0) {
  478. XEvent event;
  479. XNextEvent(dpy, &event);
  480. op = handle_event(dpy, win, &event);
  481. if (op == EXIT)
  482. return;
  483. else if (op == DRAW)
  484. break;
  485. }
  486. draw_frame(dpy, win);
  487. }
  488. }
  489. static void
  490. usage(void)
  491. {
  492. printf("Usage:\n");
  493. printf(" -display <displayname> set the display to run on\n");
  494. printf(" -stereo run in stereo mode\n");
  495. printf(" -fullscreen run in fullscreen mode\n");
  496. printf(" -info display OpenGL renderer info\n");
  497. printf(" -geometry WxH+X+Y window geometry\n");
  498. }
  499. int
  500. main(int argc, char *argv[])
  501. {
  502. unsigned int winWidth = 300, winHeight = 300;
  503. int x = 0, y = 0;
  504. Display *dpy;
  505. Window win;
  506. GLXContext ctx;
  507. char *dpyName = NULL;
  508. GLboolean printInfo = GL_FALSE;
  509. int i;
  510. for (i = 1; i < argc; i++) {
  511. if (strcmp(argv[i], "-display") == 0) {
  512. dpyName = argv[i+1];
  513. i++;
  514. }
  515. else if (strcmp(argv[i], "-info") == 0) {
  516. printInfo = GL_TRUE;
  517. }
  518. else if (strcmp(argv[i], "-stereo") == 0) {
  519. stereo = GL_TRUE;
  520. }
  521. else if (strcmp(argv[i], "-fullscreen") == 0) {
  522. fullscreen = GL_TRUE;
  523. }
  524. else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
  525. XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
  526. i++;
  527. }
  528. else {
  529. usage();
  530. return -1;
  531. }
  532. }
  533. dpy = XOpenDisplay(dpyName);
  534. if (!dpy) {
  535. printf("Error: couldn't open display %s\n",
  536. dpyName ? dpyName : getenv("DISPLAY"));
  537. return -1;
  538. }
  539. make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
  540. XMapWindow(dpy, win);
  541. glXMakeCurrent(dpy, win, ctx);
  542. if (printInfo) {
  543. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  544. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  545. printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  546. printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
  547. }
  548. init();
  549. /* Set initial projection/viewing transformation.
  550. * We can't be sure we'll get a ConfigureNotify event when the window
  551. * first appears.
  552. */
  553. reshape(winWidth, winHeight);
  554. event_loop(dpy, win);
  555. glDeleteLists(gear1, 1);
  556. glDeleteLists(gear2, 1);
  557. glDeleteLists(gear3, 1);
  558. glXDestroyContext(dpy, ctx);
  559. XDestroyWindow(dpy, win);
  560. XCloseDisplay(dpy);
  561. return 0;
  562. }