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