PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/external/glew-1.9.0/src/visualinfo.c

https://gitlab.com/dannywillems/mass_collide
C | 1178 lines | 934 code | 56 blank | 188 comment | 375 complexity | bf48e8de42f717d8d990cd738579ba36 MD5 | raw file
  1. /*
  2. ** visualinfo.c
  3. **
  4. ** Copyright (C) Nate Robins, 1997
  5. ** Michael Wimmer, 1999
  6. ** Milan Ikits, 2002-2008
  7. **
  8. ** visualinfo is a small utility that displays all available visuals,
  9. ** aka. pixelformats, in an OpenGL system along with renderer version
  10. ** information. It shows a table of all the visuals that support OpenGL
  11. ** along with their capabilities. The format of the table is similar to
  12. ** that of glxinfo on Unix systems:
  13. **
  14. ** visual ~= pixel format descriptor
  15. ** id = visual id (integer from 1 - max visuals)
  16. ** tp = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)
  17. ** ac = acceleration (ge: generic, fu: full, no: none)
  18. ** fm = format (i: integer, f: float, c: color index)
  19. ** db = double buffer (y = yes)
  20. ** sw = swap method (x: exchange, c: copy, u: undefined)
  21. ** st = stereo (y = yes)
  22. ** sz = total # bits
  23. ** r = # bits of red
  24. ** g = # bits of green
  25. ** b = # bits of blue
  26. ** a = # bits of alpha
  27. ** axbf = # aux buffers
  28. ** dpth = # bits of depth
  29. ** stcl = # bits of stencil
  30. */
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <GL/glew.h>
  35. #if defined(_WIN32)
  36. #include <GL/wglew.h>
  37. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  38. #include <AGL/agl.h>
  39. #else
  40. #include <GL/glxew.h>
  41. #endif
  42. #ifdef GLEW_MX
  43. GLEWContext _glewctx;
  44. # define glewGetContext() (&_glewctx)
  45. # ifdef _WIN32
  46. WGLEWContext _wglewctx;
  47. # define wglewGetContext() (&_wglewctx)
  48. # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
  49. GLXEWContext _glxewctx;
  50. # define glxewGetContext() (&_glxewctx)
  51. # endif
  52. #endif /* GLEW_MX */
  53. typedef struct GLContextStruct
  54. {
  55. #ifdef _WIN32
  56. HWND wnd;
  57. HDC dc;
  58. HGLRC rc;
  59. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  60. AGLContext ctx, octx;
  61. #else
  62. Display* dpy;
  63. XVisualInfo* vi;
  64. GLXContext ctx;
  65. Window wnd;
  66. Colormap cmap;
  67. #endif
  68. } GLContext;
  69. void InitContext (GLContext* ctx);
  70. GLboolean CreateContext (GLContext* ctx);
  71. void DestroyContext (GLContext* ctx);
  72. void VisualInfo (GLContext* ctx);
  73. void PrintExtensions (const char* s);
  74. GLboolean ParseArgs (int argc, char** argv);
  75. int showall = 0;
  76. int displaystdout = 0;
  77. int verbose = 0;
  78. int drawableonly = 0;
  79. char* display = NULL;
  80. int visual = -1;
  81. FILE* file = 0;
  82. int
  83. main (int argc, char** argv)
  84. {
  85. GLenum err;
  86. GLContext ctx;
  87. /* ---------------------------------------------------------------------- */
  88. /* parse arguments */
  89. if (GL_TRUE == ParseArgs(argc-1, argv+1))
  90. {
  91. #if defined(_WIN32)
  92. fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
  93. fprintf(stderr, " -a: show all visuals\n");
  94. fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n");
  95. fprintf(stderr, " -pf <id>: use given pixelformat\n");
  96. fprintf(stderr, " -h: this screen\n");
  97. #else
  98. fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");
  99. fprintf(stderr, " -h: this screen\n");
  100. fprintf(stderr, " -display <display>: use given display\n");
  101. fprintf(stderr, " -visual <id>: use given visual\n");
  102. #endif
  103. return 1;
  104. }
  105. /* ---------------------------------------------------------------------- */
  106. /* create OpenGL rendering context */
  107. InitContext(&ctx);
  108. if (GL_TRUE == CreateContext(&ctx))
  109. {
  110. fprintf(stderr, "Error: CreateContext failed\n");
  111. DestroyContext(&ctx);
  112. return 1;
  113. }
  114. /* ---------------------------------------------------------------------- */
  115. /* initialize GLEW */
  116. glewExperimental = GL_TRUE;
  117. #ifdef GLEW_MX
  118. err = glewContextInit(glewGetContext());
  119. # ifdef _WIN32
  120. err = err || wglewContextInit(wglewGetContext());
  121. # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
  122. err = err || glxewContextInit(glxewGetContext());
  123. # endif
  124. #else
  125. err = glewInit();
  126. #endif
  127. if (GLEW_OK != err)
  128. {
  129. fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
  130. DestroyContext(&ctx);
  131. return 1;
  132. }
  133. /* ---------------------------------------------------------------------- */
  134. /* open file */
  135. #if defined(_WIN32)
  136. if (!displaystdout)
  137. file = fopen("visualinfo.txt", "w");
  138. if (file == NULL)
  139. file = stdout;
  140. #else
  141. file = stdout;
  142. #endif
  143. /* ---------------------------------------------------------------------- */
  144. /* output header information */
  145. /* OpenGL extensions */
  146. fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR));
  147. fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER));
  148. fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION));
  149. fprintf(file, "OpenGL extensions (GL_): \n");
  150. PrintExtensions((char*)glGetString(GL_EXTENSIONS));
  151. #ifndef GLEW_NO_GLU
  152. /* GLU extensions */
  153. fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION));
  154. fprintf(file, "GLU extensions (GLU_): \n");
  155. PrintExtensions((char*)gluGetString(GLU_EXTENSIONS));
  156. #endif
  157. /* ---------------------------------------------------------------------- */
  158. /* extensions string */
  159. #if defined(_WIN32)
  160. /* WGL extensions */
  161. if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)
  162. {
  163. fprintf(file, "WGL extensions (WGL_): \n");
  164. PrintExtensions(wglGetExtensionsStringARB ?
  165. (char*)wglGetExtensionsStringARB(ctx.dc) :
  166. (char*)wglGetExtensionsStringEXT());
  167. }
  168. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  169. #else
  170. /* GLX extensions */
  171. fprintf(file, "GLX extensions (GLX_): \n");
  172. PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),
  173. DefaultScreen(glXGetCurrentDisplay())));
  174. #endif
  175. /* ---------------------------------------------------------------------- */
  176. /* enumerate all the formats */
  177. VisualInfo(&ctx);
  178. /* ---------------------------------------------------------------------- */
  179. /* release resources */
  180. DestroyContext(&ctx);
  181. if (file != stdout)
  182. fclose(file);
  183. return 0;
  184. }
  185. /* do the magic to separate all extensions with comma's, except
  186. for the last one that _may_ terminate in a space. */
  187. void PrintExtensions (const char* s)
  188. {
  189. char t[80];
  190. int i=0;
  191. char* p=0;
  192. t[79] = '\0';
  193. while (*s)
  194. {
  195. t[i++] = *s;
  196. if(*s == ' ')
  197. {
  198. if (*(s+1) != '\0') {
  199. t[i-1] = ',';
  200. t[i] = ' ';
  201. p = &t[i++];
  202. }
  203. else /* zoinks! last one terminated in a space! */
  204. {
  205. t[i-1] = '\0';
  206. }
  207. }
  208. if(i > 80 - 5)
  209. {
  210. *p = t[i] = '\0';
  211. fprintf(file, " %s\n", t);
  212. p++;
  213. i = (int)strlen(p);
  214. strcpy(t, p);
  215. }
  216. s++;
  217. }
  218. t[i] = '\0';
  219. fprintf(file, " %s.\n", t);
  220. }
  221. /* ---------------------------------------------------------------------- */
  222. #if defined(_WIN32)
  223. void
  224. VisualInfoARB (GLContext* ctx)
  225. {
  226. int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;
  227. int i, pf, maxpf;
  228. unsigned int c;
  229. /* to get pbuffer capable pixel formats */
  230. attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;
  231. attrib[1] = GL_TRUE;
  232. attrib[2] = 0;
  233. wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);
  234. /* query number of pixel formats */
  235. attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
  236. wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);
  237. maxpf = value[0];
  238. for (i=0; i<32; i++)
  239. value[i] = 0;
  240. attrib[0] = WGL_SUPPORT_OPENGL_ARB;
  241. attrib[1] = WGL_DRAW_TO_WINDOW_ARB;
  242. attrib[2] = WGL_DRAW_TO_BITMAP_ARB;
  243. attrib[3] = WGL_ACCELERATION_ARB;
  244. /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
  245. attrib[4] = WGL_SWAP_METHOD_ARB;
  246. /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
  247. attrib[5] = WGL_DOUBLE_BUFFER_ARB;
  248. attrib[6] = WGL_STEREO_ARB;
  249. attrib[7] = WGL_PIXEL_TYPE_ARB;
  250. /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
  251. WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
  252. /* Color buffer information */
  253. attrib[8] = WGL_COLOR_BITS_ARB;
  254. attrib[9] = WGL_RED_BITS_ARB;
  255. attrib[10] = WGL_GREEN_BITS_ARB;
  256. attrib[11] = WGL_BLUE_BITS_ARB;
  257. attrib[12] = WGL_ALPHA_BITS_ARB;
  258. /* Accumulation buffer information */
  259. attrib[13] = WGL_ACCUM_BITS_ARB;
  260. attrib[14] = WGL_ACCUM_RED_BITS_ARB;
  261. attrib[15] = WGL_ACCUM_GREEN_BITS_ARB;
  262. attrib[16] = WGL_ACCUM_BLUE_BITS_ARB;
  263. attrib[17] = WGL_ACCUM_ALPHA_BITS_ARB;
  264. /* Depth, stencil, and aux buffer information */
  265. attrib[18] = WGL_DEPTH_BITS_ARB;
  266. attrib[19] = WGL_STENCIL_BITS_ARB;
  267. attrib[20] = WGL_AUX_BUFFERS_ARB;
  268. /* Layer information */
  269. attrib[21] = WGL_NUMBER_OVERLAYS_ARB;
  270. attrib[22] = WGL_NUMBER_UNDERLAYS_ARB;
  271. attrib[23] = WGL_SWAP_LAYER_BUFFERS_ARB;
  272. attrib[24] = WGL_SAMPLES_ARB;
  273. attrib[25] = WGL_SUPPORT_GDI_ARB;
  274. n_attrib = 26;
  275. if (WGLEW_ARB_pbuffer)
  276. {
  277. attrib[n_attrib] = WGL_DRAW_TO_PBUFFER_ARB;
  278. n_pbuffer = n_attrib;
  279. n_attrib++;
  280. }
  281. if (WGLEW_NV_float_buffer)
  282. {
  283. attrib[n_attrib] = WGL_FLOAT_COMPONENTS_NV;
  284. n_float = n_attrib;
  285. n_attrib++;
  286. }
  287. if (!verbose)
  288. {
  289. /* print table header */
  290. fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
  291. fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
  292. fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
  293. fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
  294. /* loop through all the pixel formats */
  295. for(i = 1; i <= maxpf; i++)
  296. {
  297. wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);
  298. /* only describe this format if it supports OpenGL */
  299. if (!value[0]) continue;
  300. /* by default show only fully accelerated window or pbuffer capable visuals */
  301. if (!showall
  302. && ((value[2] && !value[1])
  303. || (!WGLEW_ARB_pbuffer || !value[n_pbuffer])
  304. || (value[3] != WGL_FULL_ACCELERATION_ARB))) continue;
  305. /* print out the information for this visual */
  306. /* visual id */
  307. fprintf(file, " |% 4d | ", i);
  308. /* visual type */
  309. if (value[1])
  310. {
  311. if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "wp ");
  312. else fprintf(file, "wn ");
  313. }
  314. else
  315. {
  316. if (value[2]) fprintf(file, "bm ");
  317. else if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "pb ");
  318. }
  319. /* acceleration */
  320. fprintf(file, "%s ", value[3] == WGL_FULL_ACCELERATION_ARB ? "fu" :
  321. value[3] == WGL_GENERIC_ACCELERATION_ARB ? "ge" :
  322. value[3] == WGL_NO_ACCELERATION_ARB ? "no" : ". ");
  323. /* gdi support */
  324. fprintf(file, " %c ", value[25] ? 'y' : '.');
  325. /* format */
  326. if (WGLEW_NV_float_buffer && value[n_float]) fprintf(file, " f ");
  327. else if (WGLEW_ATI_pixel_format_float && value[7] == WGL_TYPE_RGBA_FLOAT_ATI) fprintf(file, " f ");
  328. else if (value[7] == WGL_TYPE_RGBA_ARB) fprintf(file, " i ");
  329. else if (value[7] == WGL_TYPE_COLORINDEX_ARB) fprintf(file, " c ");
  330. else if (value[7] == WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT) fprintf(file," p ");
  331. else fprintf(file," ? ");
  332. /* double buffer */
  333. fprintf(file, " %c ", value[5] ? 'y' : '.');
  334. /* swap method */
  335. if (value[4] == WGL_SWAP_EXCHANGE_ARB) fprintf(file, " x ");
  336. else if (value[4] == WGL_SWAP_COPY_ARB) fprintf(file, " c ");
  337. else if (value[4] == WGL_SWAP_UNDEFINED_ARB) fprintf(file, " . ");
  338. else fprintf(file, " . ");
  339. /* stereo */
  340. fprintf(file, " %c ", value[6] ? 'y' : '.');
  341. /* multisample */
  342. if (value[24] > 0)
  343. fprintf(file, "%2d | ", value[24]);
  344. else
  345. fprintf(file, " . | ");
  346. /* color size */
  347. if (value[8]) fprintf(file, "%3d ", value[8]);
  348. else fprintf(file, " . ");
  349. /* red */
  350. if (value[9]) fprintf(file, "%2d ", value[9]);
  351. else fprintf(file, " . ");
  352. /* green */
  353. if (value[10]) fprintf(file, "%2d ", value[10]);
  354. else fprintf(file, " . ");
  355. /* blue */
  356. if (value[11]) fprintf(file, "%2d ", value[11]);
  357. else fprintf(file, " . ");
  358. /* alpha */
  359. if (value[12]) fprintf(file, "%2d | ", value[12]);
  360. else fprintf(file, " . | ");
  361. /* aux buffers */
  362. if (value[20]) fprintf(file, "%2d ", value[20]);
  363. else fprintf(file, " . ");
  364. /* depth */
  365. if (value[18]) fprintf(file, "%2d ", value[18]);
  366. else fprintf(file, " . ");
  367. /* stencil */
  368. if (value[19]) fprintf(file, "%2d | ", value[19]);
  369. else fprintf(file, " . | ");
  370. /* accum size */
  371. if (value[13]) fprintf(file, "%3d ", value[13]);
  372. else fprintf(file, " . ");
  373. /* accum red */
  374. if (value[14]) fprintf(file, "%2d ", value[14]);
  375. else fprintf(file, " . ");
  376. /* accum green */
  377. if (value[15]) fprintf(file, "%2d ", value[15]);
  378. else fprintf(file, " . ");
  379. /* accum blue */
  380. if (value[16]) fprintf(file, "%2d ", value[16]);
  381. else fprintf(file, " . ");
  382. /* accum alpha */
  383. if (value[17]) fprintf(file, "%2d | ", value[17]);
  384. else fprintf(file, " . | ");
  385. /* overlay */
  386. if (value[21]) fprintf(file, "%2d ", value[21]);
  387. else fprintf(file, " . ");
  388. /* underlay */
  389. if (value[22]) fprintf(file, "%2d ", value[22]);
  390. else fprintf(file, " . ");
  391. /* layer swap */
  392. if (value[23]) fprintf(file, "y ");
  393. else fprintf(file, " . ");
  394. fprintf(file, "|\n");
  395. }
  396. /* print table footer */
  397. fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
  398. fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
  399. fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
  400. fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
  401. }
  402. else /* verbose */
  403. {
  404. #if 0
  405. fprintf(file, "\n");
  406. /* loop through all the pixel formats */
  407. for(i = 1; i <= maxpf; i++)
  408. {
  409. DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  410. /* only describe this format if it supports OpenGL */
  411. if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
  412. || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
  413. fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
  414. pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
  415. fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
  416. fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
  417. fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
  418. fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
  419. fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
  420. fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
  421. fprintf(file, " Opaque.\n");
  422. }
  423. #endif
  424. }
  425. }
  426. void
  427. VisualInfoGDI (GLContext* ctx)
  428. {
  429. int i, maxpf;
  430. PIXELFORMATDESCRIPTOR pfd;
  431. /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
  432. number of pixel formats */
  433. maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
  434. if (!verbose)
  435. {
  436. fprintf(file, "-----------------------------------------------------------------------------\n");
  437. fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
  438. fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
  439. fprintf(file, "-----------------------------------------------------------------------------\n");
  440. /* loop through all the pixel formats */
  441. for(i = 1; i <= maxpf; i++)
  442. {
  443. DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  444. /* only describe this format if it supports OpenGL */
  445. if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
  446. || (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
  447. /* other criteria could be tested here for actual pixel format
  448. choosing in an application:
  449. for (...each pixel format...) {
  450. if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
  451. pfd.dwFlags & PFD_DOUBLEBUFFER &&
  452. pfd.cDepthBits >= 24 &&
  453. pfd.cColorBits >= 24)
  454. {
  455. goto found;
  456. }
  457. }
  458. ... not found so exit ...
  459. found:
  460. ... found so use it ...
  461. */
  462. /* print out the information for this pixel format */
  463. fprintf(file, "0x%02x ", i);
  464. fprintf(file, "%3d ", pfd.cColorBits);
  465. if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");
  466. else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");
  467. else fprintf(file, "pb ");
  468. /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
  469. fprintf(file, " . ");
  470. fprintf(file, "%3d ", pfd.cColorBits);
  471. /* bReserved field indicates number of over/underlays */
  472. if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);
  473. else fprintf(file, " . ");
  474. fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
  475. fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
  476. fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
  477. /* added: */
  478. fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');
  479. fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');
  480. if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)
  481. fprintf(file, "%2d ", pfd.cRedBits);
  482. else fprintf(file, " . ");
  483. if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)
  484. fprintf(file, "%2d ", pfd.cGreenBits);
  485. else fprintf(file, " . ");
  486. if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)
  487. fprintf(file, "%2d ", pfd.cBlueBits);
  488. else fprintf(file, " . ");
  489. if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)
  490. fprintf(file, "%2d ", pfd.cAlphaBits);
  491. else fprintf(file, " . ");
  492. if(pfd.cAuxBuffers) fprintf(file, "%2d ", pfd.cAuxBuffers);
  493. else fprintf(file, " . ");
  494. if(pfd.cDepthBits) fprintf(file, "%2d ", pfd.cDepthBits);
  495. else fprintf(file, " . ");
  496. if(pfd.cStencilBits) fprintf(file, "%2d ", pfd.cStencilBits);
  497. else fprintf(file, " . ");
  498. if(pfd.cAccumBits) fprintf(file, "%3d ", pfd.cAccumBits);
  499. else fprintf(file, " . ");
  500. if(pfd.cAccumRedBits) fprintf(file, "%2d ", pfd.cAccumRedBits);
  501. else fprintf(file, " . ");
  502. if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);
  503. else fprintf(file, " . ");
  504. if(pfd.cAccumBlueBits) fprintf(file, "%2d ", pfd.cAccumBlueBits);
  505. else fprintf(file, " . ");
  506. if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);
  507. else fprintf(file, " . ");
  508. /* no multisample in win32 */
  509. fprintf(file, " . .\n");
  510. }
  511. /* print table footer */
  512. fprintf(file, "-----------------------------------------------------------------------------\n");
  513. fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
  514. fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
  515. fprintf(file, "-----------------------------------------------------------------------------\n");
  516. }
  517. else /* verbose */
  518. {
  519. fprintf(file, "\n");
  520. /* loop through all the pixel formats */
  521. for(i = 1; i <= maxpf; i++)
  522. {
  523. DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  524. /* only describe this format if it supports OpenGL */
  525. if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
  526. || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
  527. fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
  528. pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
  529. fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%ld stereo=%ld\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
  530. fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
  531. fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
  532. fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
  533. fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
  534. fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
  535. fprintf(file, " Opaque.\n");
  536. }
  537. }
  538. }
  539. void
  540. VisualInfo (GLContext* ctx)
  541. {
  542. if (WGLEW_ARB_pixel_format)
  543. VisualInfoARB(ctx);
  544. else
  545. VisualInfoGDI(ctx);
  546. }
  547. /* ---------------------------------------------------------------------- */
  548. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  549. void
  550. VisualInfo (GLContext* ctx)
  551. {
  552. /*
  553. int attrib[] = { AGL_RGBA, AGL_NONE };
  554. AGLPixelFormat pf;
  555. GLint value;
  556. pf = aglChoosePixelFormat(NULL, 0, attrib);
  557. while (pf != NULL)
  558. {
  559. aglDescribePixelFormat(pf, GL_RGBA, &value);
  560. fprintf(stderr, "%d\n", value);
  561. pf = aglNextPixelFormat(pf);
  562. }
  563. */
  564. }
  565. #else /* GLX */
  566. void
  567. VisualInfo (GLContext* ctx)
  568. {
  569. int n_fbc;
  570. GLXFBConfig* fbc;
  571. int value, ret, i;
  572. fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);
  573. if (fbc)
  574. {
  575. if (!verbose)
  576. {
  577. /* print table header */
  578. fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
  579. fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
  580. fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
  581. fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
  582. /* loop through all the fbcs */
  583. for (i=0; i<n_fbc; i++)
  584. {
  585. /* print out the information for this fbc */
  586. /* visual id */
  587. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FBCONFIG_ID, &value);
  588. if (ret != Success)
  589. {
  590. fprintf(file, "| ? |");
  591. }
  592. else
  593. {
  594. fprintf(file, " |% 4d | ", value);
  595. }
  596. /* visual type */
  597. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DRAWABLE_TYPE, &value);
  598. if (ret != Success)
  599. {
  600. fprintf(file, " ? ");
  601. }
  602. else
  603. {
  604. if (value & GLX_WINDOW_BIT)
  605. {
  606. if (value & GLX_PBUFFER_BIT)
  607. {
  608. fprintf(file, "wp ");
  609. }
  610. else
  611. {
  612. fprintf(file, "wn ");
  613. }
  614. }
  615. else
  616. {
  617. if (value & GLX_PBUFFER_BIT)
  618. {
  619. fprintf(file, "pb ");
  620. }
  621. else if (value & GLX_PIXMAP_BIT)
  622. {
  623. fprintf(file, "pm ");
  624. }
  625. else
  626. {
  627. fprintf(file, " ? ");
  628. }
  629. }
  630. }
  631. /* x renderable */
  632. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_RENDERABLE, &value);
  633. if (ret != Success)
  634. {
  635. fprintf(file, " ? ");
  636. }
  637. else
  638. {
  639. fprintf(file, value ? " y " : " n ");
  640. }
  641. /* class */
  642. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_VISUAL_TYPE, &value);
  643. if (ret != Success)
  644. {
  645. fprintf(file, " ? ");
  646. }
  647. else
  648. {
  649. if (GLX_TRUE_COLOR == value)
  650. fprintf(file, "tc ");
  651. else if (GLX_DIRECT_COLOR == value)
  652. fprintf(file, "dc ");
  653. else if (GLX_PSEUDO_COLOR == value)
  654. fprintf(file, "pc ");
  655. else if (GLX_STATIC_COLOR == value)
  656. fprintf(file, "sc ");
  657. else if (GLX_GRAY_SCALE == value)
  658. fprintf(file, "gs ");
  659. else if (GLX_STATIC_GRAY == value)
  660. fprintf(file, "sg ");
  661. else if (GLX_X_VISUAL_TYPE == value)
  662. fprintf(file, " . ");
  663. else
  664. fprintf(file, " ? ");
  665. }
  666. /* format */
  667. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RENDER_TYPE, &value);
  668. if (ret != Success)
  669. {
  670. fprintf(file, " ? ");
  671. }
  672. else
  673. {
  674. if (GLXEW_NV_float_buffer)
  675. {
  676. int ret2, value2;
  677. ret2 = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FLOAT_COMPONENTS_NV, &value2);
  678. if (Success == ret2 && GL_TRUE == value2)
  679. {
  680. fprintf(file, " f ");
  681. }
  682. else if (value & GLX_RGBA_BIT)
  683. fprintf(file, " i ");
  684. else if (value & GLX_COLOR_INDEX_BIT)
  685. fprintf(file, " c ");
  686. else
  687. fprintf(file, " ? ");
  688. }
  689. else
  690. {
  691. if (value & GLX_RGBA_FLOAT_ATI_BIT)
  692. fprintf(file, " f ");
  693. else if (value & GLX_RGBA_BIT)
  694. fprintf(file, " i ");
  695. else if (value & GLX_COLOR_INDEX_BIT)
  696. fprintf(file, " c ");
  697. else
  698. fprintf(file, " ? ");
  699. }
  700. }
  701. /* double buffer */
  702. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DOUBLEBUFFER, &value);
  703. fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
  704. /* stereo */
  705. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STEREO, &value);
  706. fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
  707. /* level */
  708. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_LEVEL, &value);
  709. if (Success != ret)
  710. {
  711. fprintf(file, " ? ");
  712. }
  713. else
  714. {
  715. fprintf(file, "%2d ", value);
  716. }
  717. /* transparency */
  718. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_TRANSPARENT_TYPE, &value);
  719. if (Success != ret)
  720. {
  721. fprintf(file, " ? | ");
  722. }
  723. else
  724. {
  725. if (GLX_TRANSPARENT_RGB == value)
  726. fprintf(file, " r | ");
  727. else if (GLX_TRANSPARENT_INDEX == value)
  728. fprintf(file, " i | ");
  729. else if (GLX_NONE == value)
  730. fprintf(file, " . | ");
  731. else
  732. fprintf(file, " ? | ");
  733. }
  734. /* color size */
  735. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BUFFER_SIZE, &value);
  736. if (Success != ret)
  737. {
  738. fprintf(file, " ? ");
  739. }
  740. else
  741. {
  742. if (value)
  743. fprintf(file, "%3d ", value);
  744. else
  745. fprintf(file, " . ");
  746. }
  747. /* red size */
  748. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RED_SIZE, &value);
  749. if (Success != ret)
  750. {
  751. fprintf(file, " ? ");
  752. }
  753. else
  754. {
  755. if (value)
  756. fprintf(file, "%2d ", value);
  757. else
  758. fprintf(file, " . ");
  759. }
  760. /* green size */
  761. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_GREEN_SIZE, &value);
  762. if (Success != ret)
  763. {
  764. fprintf(file, " ? ");
  765. }
  766. else
  767. {
  768. if (value)
  769. fprintf(file, "%2d ", value);
  770. else
  771. fprintf(file, " . ");
  772. }
  773. /* blue size */
  774. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BLUE_SIZE, &value);
  775. if (Success != ret)
  776. {
  777. fprintf(file, " ? ");
  778. }
  779. else
  780. {
  781. if (value)
  782. fprintf(file, "%2d ", value);
  783. else
  784. fprintf(file, " . ");
  785. }
  786. /* alpha size */
  787. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ALPHA_SIZE, &value);
  788. if (Success != ret)
  789. {
  790. fprintf(file, " ? | ");
  791. }
  792. else
  793. {
  794. if (value)
  795. fprintf(file, "%2d | ", value);
  796. else
  797. fprintf(file, " . | ");
  798. }
  799. /* aux buffers */
  800. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_AUX_BUFFERS, &value);
  801. if (Success != ret)
  802. {
  803. fprintf(file, " ? ");
  804. }
  805. else
  806. {
  807. if (value)
  808. fprintf(file, "%2d ", value);
  809. else
  810. fprintf(file, " . ");
  811. }
  812. /* depth size */
  813. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DEPTH_SIZE, &value);
  814. if (Success != ret)
  815. {
  816. fprintf(file, " ? ");
  817. }
  818. else
  819. {
  820. if (value)
  821. fprintf(file, "%2d ", value);
  822. else
  823. fprintf(file, " . ");
  824. }
  825. /* stencil size */
  826. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STENCIL_SIZE, &value);
  827. if (Success != ret)
  828. {
  829. fprintf(file, " ? | ");
  830. }
  831. else
  832. {
  833. if (value)
  834. fprintf(file, "%2d | ", value);
  835. else
  836. fprintf(file, " . | ");
  837. }
  838. /* accum red size */
  839. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_RED_SIZE, &value);
  840. if (Success != ret)
  841. {
  842. fprintf(file, " ? ");
  843. }
  844. else
  845. {
  846. if (value)
  847. fprintf(file, "%2d ", value);
  848. else
  849. fprintf(file, " . ");
  850. }
  851. /* accum green size */
  852. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_GREEN_SIZE, &value);
  853. if (Success != ret)
  854. {
  855. fprintf(file, " ? ");
  856. }
  857. else
  858. {
  859. if (value)
  860. fprintf(file, "%2d ", value);
  861. else
  862. fprintf(file, " . ");
  863. }
  864. /* accum blue size */
  865. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_BLUE_SIZE, &value);
  866. if (Success != ret)
  867. {
  868. fprintf(file, " ? ");
  869. }
  870. else
  871. {
  872. if (value)
  873. fprintf(file, "%2d ", value);
  874. else
  875. fprintf(file, " . ");
  876. }
  877. /* accum alpha size */
  878. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_ALPHA_SIZE, &value);
  879. if (Success != ret)
  880. {
  881. fprintf(file, " ? | ");
  882. }
  883. else
  884. {
  885. if (value)
  886. fprintf(file, "%2d | ", value);
  887. else
  888. fprintf(file, " . | ");
  889. }
  890. /* multisample */
  891. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLES, &value);
  892. if (Success != ret)
  893. {
  894. fprintf(file, " ? ");
  895. }
  896. else
  897. {
  898. fprintf(file, "%2d ", value);
  899. }
  900. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLE_BUFFERS, &value);
  901. if (Success != ret)
  902. {
  903. fprintf(file, " ? | ");
  904. }
  905. else
  906. {
  907. fprintf(file, "%2d | ", value);
  908. }
  909. /* caveat */
  910. ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_CONFIG_CAVEAT, &value);
  911. if (Success != ret)
  912. {
  913. fprintf(file, "???? |");
  914. }
  915. else
  916. {
  917. if (GLX_NONE == value)
  918. fprintf(file, "none |\n");
  919. else if (GLX_SLOW_CONFIG == value)
  920. fprintf(file, "slow |\n");
  921. else if (GLX_NON_CONFORMANT_CONFIG == value)
  922. fprintf(file, "ncft |\n");
  923. else
  924. fprintf(file, "???? |\n");
  925. }
  926. }
  927. /* print table footer */
  928. fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
  929. fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
  930. fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
  931. fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
  932. }
  933. }
  934. }
  935. #endif
  936. /* ------------------------------------------------------------------------ */
  937. #if defined(_WIN32)
  938. void InitContext (GLContext* ctx)
  939. {
  940. ctx->wnd = NULL;
  941. ctx->dc = NULL;
  942. ctx->rc = NULL;
  943. }
  944. GLboolean CreateContext (GLContext* ctx)
  945. {
  946. WNDCLASS wc;
  947. PIXELFORMATDESCRIPTOR pfd;
  948. /* check for input */
  949. if (NULL == ctx) return GL_TRUE;
  950. /* register window class */
  951. ZeroMemory(&wc, sizeof(WNDCLASS));
  952. wc.hInstance = GetModuleHandle(NULL);
  953. wc.lpfnWndProc = DefWindowProc;
  954. wc.lpszClassName = "GLEW";
  955. if (0 == RegisterClass(&wc)) return GL_TRUE;
  956. /* create window */
  957. ctx->wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT,
  958. CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
  959. GetModuleHandle(NULL), NULL);
  960. if (NULL == ctx->wnd) return GL_TRUE;
  961. /* get the device context */
  962. ctx->dc = GetDC(ctx->wnd);
  963. if (NULL == ctx->dc) return GL_TRUE;
  964. /* find pixel format */
  965. ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
  966. if (visual == -1) /* find default */
  967. {
  968. pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  969. pfd.nVersion = 1;
  970. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
  971. visual = ChoosePixelFormat(ctx->dc, &pfd);
  972. if (0 == visual) return GL_TRUE;
  973. }
  974. /* set the pixel format for the dc */
  975. if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;
  976. /* create rendering context */
  977. ctx->rc = wglCreateContext(ctx->dc);
  978. if (NULL == ctx->rc) return GL_TRUE;
  979. if (FALSE == wglMakeCurrent(ctx->dc, ctx->rc)) return GL_TRUE;
  980. return GL_FALSE;
  981. }
  982. void DestroyContext (GLContext* ctx)
  983. {
  984. if (NULL == ctx) return;
  985. if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);
  986. if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());
  987. if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
  988. if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);
  989. UnregisterClass("GLEW", GetModuleHandle(NULL));
  990. }
  991. /* ------------------------------------------------------------------------ */
  992. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  993. void InitContext (GLContext* ctx)
  994. {
  995. ctx->ctx = NULL;
  996. ctx->octx = NULL;
  997. }
  998. GLboolean CreateContext (GLContext* ctx)
  999. {
  1000. int attrib[] = { AGL_RGBA, AGL_NONE };
  1001. AGLPixelFormat pf;
  1002. /* check input */
  1003. if (NULL == ctx) return GL_TRUE;
  1004. /*int major, minor;
  1005. SetPortWindowPort(wnd);
  1006. aglGetVersion(&major, &minor);
  1007. fprintf(stderr, "GL %d.%d\n", major, minor);*/
  1008. pf = aglChoosePixelFormat(NULL, 0, attrib);
  1009. if (NULL == pf) return GL_TRUE;
  1010. ctx->ctx = aglCreateContext(pf, NULL);
  1011. if (NULL == ctx->ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
  1012. aglDestroyPixelFormat(pf);
  1013. /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
  1014. ctx->octx = aglGetCurrentContext();
  1015. if (GL_FALSE == aglSetCurrentContext(ctx->ctx)) return GL_TRUE;
  1016. return GL_FALSE;
  1017. }
  1018. void DestroyContext (GLContext* ctx)
  1019. {
  1020. if (NULL == ctx) return;
  1021. aglSetCurrentContext(ctx->octx);
  1022. if (NULL != ctx->ctx) aglDestroyContext(ctx->ctx);
  1023. }
  1024. /* ------------------------------------------------------------------------ */
  1025. #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
  1026. void InitContext (GLContext* ctx)
  1027. {
  1028. ctx->dpy = NULL;
  1029. ctx->vi = NULL;
  1030. ctx->ctx = NULL;
  1031. ctx->wnd = 0;
  1032. ctx->cmap = 0;
  1033. }
  1034. GLboolean CreateContext (GLContext* ctx)
  1035. {
  1036. int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
  1037. int erb, evb;
  1038. XSetWindowAttributes swa;
  1039. /* check input */
  1040. if (NULL == ctx) return GL_TRUE;
  1041. /* open display */
  1042. ctx->dpy = XOpenDisplay(display);
  1043. if (NULL == ctx->dpy) return GL_TRUE;
  1044. /* query for glx */
  1045. if (!glXQueryExtension(ctx->dpy, &erb, &evb)) return GL_TRUE;
  1046. /* choose visual */
  1047. ctx->vi = glXChooseVisual(ctx->dpy, DefaultScreen(ctx->dpy), attrib);
  1048. if (NULL == ctx->vi) return GL_TRUE;
  1049. /* create context */
  1050. ctx->ctx = glXCreateContext(ctx->dpy, ctx->vi, None, True);
  1051. if (NULL == ctx->ctx) return GL_TRUE;
  1052. /* create window */
  1053. /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
  1054. ctx->cmap = XCreateColormap(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
  1055. ctx->vi->visual, AllocNone);
  1056. swa.border_pixel = 0;
  1057. swa.colormap = ctx->cmap;
  1058. ctx->wnd = XCreateWindow(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
  1059. 0, 0, 1, 1, 0, ctx->vi->depth, InputOutput, ctx->vi->visual,
  1060. CWBorderPixel | CWColormap, &swa);
  1061. /* make context current */
  1062. if (!glXMakeCurrent(ctx->dpy, ctx->wnd, ctx->ctx)) return GL_TRUE;
  1063. return GL_FALSE;
  1064. }
  1065. void DestroyContext (GLContext* ctx)
  1066. {
  1067. if (NULL != ctx->dpy && NULL != ctx->ctx) glXDestroyContext(ctx->dpy, ctx->ctx);
  1068. if (NULL != ctx->dpy && 0 != ctx->wnd) XDestroyWindow(ctx->dpy, ctx->wnd);
  1069. if (NULL != ctx->dpy && 0 != ctx->cmap) XFreeColormap(ctx->dpy, ctx->cmap);
  1070. if (NULL != ctx->vi) XFree(ctx->vi);
  1071. if (NULL != ctx->dpy) XCloseDisplay(ctx->dpy);
  1072. }
  1073. #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
  1074. GLboolean ParseArgs (int argc, char** argv)
  1075. {
  1076. int p = 0;
  1077. while (p < argc)
  1078. {
  1079. #if defined(_WIN32)
  1080. if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
  1081. {
  1082. if (++p >= argc) return GL_TRUE;
  1083. display = NULL;
  1084. visual = strtol(argv[p], NULL, 0);
  1085. }
  1086. else if (!strcmp(argv[p], "-a"))
  1087. {
  1088. showall = 1;
  1089. }
  1090. else if (!strcmp(argv[p], "-s"))
  1091. {
  1092. displaystdout = 1;
  1093. }
  1094. else if (!strcmp(argv[p], "-h"))
  1095. {
  1096. return GL_TRUE;
  1097. }
  1098. else
  1099. return GL_TRUE;
  1100. #else
  1101. if (!strcmp(argv[p], "-display"))
  1102. {
  1103. if (++p >= argc) return GL_TRUE;
  1104. display = argv[p];
  1105. }
  1106. else if (!strcmp(argv[p], "-visual"))
  1107. {
  1108. if (++p >= argc) return GL_TRUE;
  1109. visual = (int)strtol(argv[p], NULL, 0);
  1110. }
  1111. else if (!strcmp(argv[p], "-h"))
  1112. {
  1113. return GL_TRUE;
  1114. }
  1115. else
  1116. return GL_TRUE;
  1117. #endif
  1118. p++;
  1119. }
  1120. return GL_FALSE;
  1121. }