4 ** Copyright (C) Nate Robins, 1997
5 ** Michael Wimmer, 1999
6 ** Milan Ikits, 2002-2008
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:
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)
24 ** g = # bits of green
26 ** a = # bits of alpha
27 ** axbf = # aux buffers
28 ** dpth = # bits of depth
29 ** stcl = # bits of stencil
38 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
46 # define glewGetContext() (&_glewctx)
48 WGLEWContext _wglewctx
;
49 # define wglewGetContext() (&_wglewctx)
50 # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
51 GLXEWContext _glxewctx
;
52 # define glxewGetContext() (&_glxewctx)
56 typedef struct GLContextStruct
62 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
73 void InitContext (GLContext
* ctx
);
74 GLboolean
CreateContext (GLContext
* ctx
);
75 void DestroyContext (GLContext
* ctx
);
76 void VisualInfo (GLContext
* ctx
);
77 void PrintExtensions (const char* s
);
78 GLboolean
ParseArgs (int argc
, char** argv
);
81 int displaystdout
= 0;
92 main (int argc
, char** argv
)
96 /* ---------------------------------------------------------------------- */
98 if (GL_TRUE
== ParseArgs(argc
-1, argv
+1))
101 fprintf(stderr
, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
102 fprintf(stderr
, " -a: show all visuals\n");
103 fprintf(stderr
, " -s: display to stdout instead of visualinfo.txt\n");
104 fprintf(stderr
, " -pf <id>: use given pixelformat\n");
105 fprintf(stderr
, " -h: this screen\n");
107 fprintf(stderr
, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");
108 fprintf(stderr
, " -h: this screen\n");
109 fprintf(stderr
, " -display <display>: use given display\n");
110 fprintf(stderr
, " -visual <id>: use given visual\n");
115 /* ---------------------------------------------------------------------- */
116 /* create OpenGL rendering context */
118 if (GL_TRUE
== CreateContext(&ctx
))
120 fprintf(stderr
, "Error: CreateContext failed\n");
121 DestroyContext(&ctx
);
125 /* ---------------------------------------------------------------------- */
126 /* initialize GLEW */
127 glewExperimental
= GL_TRUE
;
129 err
= glewContextInit(glewGetContext());
131 err
= err
|| wglewContextInit(wglewGetContext());
132 # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
133 err
= err
|| glxewContextInit(glxewGetContext());
140 fprintf(stderr
, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err
));
141 DestroyContext(&ctx
);
145 /* ---------------------------------------------------------------------- */
149 file
= fopen("visualinfo.txt", "w");
156 /* ---------------------------------------------------------------------- */
157 /* output header information */
158 /* OpenGL extensions */
159 fprintf(file
, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR
));
160 fprintf(file
, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER
));
161 fprintf(file
, "OpenGL version string: %s\n", glGetString(GL_VERSION
));
162 fprintf(file
, "OpenGL extensions (GL_): \n");
163 PrintExtensions((char*)glGetString(GL_EXTENSIONS
));
165 fprintf(file
, "GLU version string: %s\n", gluGetString(GLU_VERSION
));
166 fprintf(file
, "GLU extensions (GLU_): \n");
167 PrintExtensions((char*)gluGetString(GLU_EXTENSIONS
));
169 /* ---------------------------------------------------------------------- */
170 /* extensions string */
173 if (WGLEW_ARB_extensions_string
|| WGLEW_EXT_extensions_string
)
175 fprintf(file
, "WGL extensions (WGL_): \n");
176 PrintExtensions(wglGetExtensionsStringARB
?
177 (char*)wglGetExtensionsStringARB(ctx
.dc
) :
178 (char*)wglGetExtensionsStringEXT());
180 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
184 fprintf(file
, "GLX extensions (GLX_): \n");
185 PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),
186 DefaultScreen(glXGetCurrentDisplay())));
189 /* ---------------------------------------------------------------------- */
190 /* enumerate all the formats */
193 /* ---------------------------------------------------------------------- */
194 /* release resources */
195 DestroyContext(&ctx
);
201 /* do the magic to separate all extensions with comma's, except
202 for the last one that _may_ terminate in a space. */
203 void PrintExtensions (const char* s
)
215 if (*(s
+1) != '\0') {
220 else /* zoinks! last one terminated in a space! */
228 fprintf(file
, " %s\n", t
);
236 fprintf(file
, " %s.\n", t
);
239 /* ---------------------------------------------------------------------- */
244 VisualInfoARB (GLContext
* ctx
)
246 int attrib
[32], value
[32], n_attrib
, n_pbuffer
=0, n_float
=0;
250 /* to get pbuffer capable pixel formats */
251 attrib
[0] = WGL_DRAW_TO_PBUFFER_ARB
;
254 wglChoosePixelFormatARB(ctx
->dc
, attrib
, 0, 1, &pf
, &c
);
255 /* query number of pixel formats */
256 attrib
[0] = WGL_NUMBER_PIXEL_FORMATS_ARB
;
257 wglGetPixelFormatAttribivARB(ctx
->dc
, 0, 0, 1, attrib
, value
);
262 attrib
[0] = WGL_SUPPORT_OPENGL_ARB
;
263 attrib
[1] = WGL_DRAW_TO_WINDOW_ARB
;
264 attrib
[2] = WGL_DRAW_TO_BITMAP_ARB
;
265 attrib
[3] = WGL_ACCELERATION_ARB
;
266 /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
267 attrib
[4] = WGL_SWAP_METHOD_ARB
;
268 /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
269 attrib
[5] = WGL_DOUBLE_BUFFER_ARB
;
270 attrib
[6] = WGL_STEREO_ARB
;
271 attrib
[7] = WGL_PIXEL_TYPE_ARB
;
272 /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
273 WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
274 /* Color buffer information */
275 attrib
[8] = WGL_COLOR_BITS_ARB
;
276 attrib
[9] = WGL_RED_BITS_ARB
;
277 attrib
[10] = WGL_GREEN_BITS_ARB
;
278 attrib
[11] = WGL_BLUE_BITS_ARB
;
279 attrib
[12] = WGL_ALPHA_BITS_ARB
;
280 /* Accumulation buffer information */
281 attrib
[13] = WGL_ACCUM_BITS_ARB
;
282 attrib
[14] = WGL_ACCUM_RED_BITS_ARB
;
283 attrib
[15] = WGL_ACCUM_GREEN_BITS_ARB
;
284 attrib
[16] = WGL_ACCUM_BLUE_BITS_ARB
;
285 attrib
[17] = WGL_ACCUM_ALPHA_BITS_ARB
;
286 /* Depth, stencil, and aux buffer information */
287 attrib
[18] = WGL_DEPTH_BITS_ARB
;
288 attrib
[19] = WGL_STENCIL_BITS_ARB
;
289 attrib
[20] = WGL_AUX_BUFFERS_ARB
;
290 /* Layer information */
291 attrib
[21] = WGL_NUMBER_OVERLAYS_ARB
;
292 attrib
[22] = WGL_NUMBER_UNDERLAYS_ARB
;
293 attrib
[23] = WGL_SWAP_LAYER_BUFFERS_ARB
;
294 attrib
[24] = WGL_SAMPLES_ARB
;
295 attrib
[25] = WGL_SUPPORT_GDI_ARB
;
297 if (WGLEW_ARB_pbuffer
)
299 attrib
[n_attrib
] = WGL_DRAW_TO_PBUFFER_ARB
;
300 n_pbuffer
= n_attrib
;
303 if (WGLEW_NV_float_buffer
)
305 attrib
[n_attrib
] = WGL_FLOAT_COMPONENTS_NV
;
312 /* print table header */
313 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
314 fprintf(file
, " | | visual | color | ax dp st | accum | layer |\n");
315 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");
316 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
317 /* loop through all the pixel formats */
318 for(i
= 1; i
<= maxpf
; i
++)
320 wglGetPixelFormatAttribivARB(ctx
->dc
, i
, 0, n_attrib
, attrib
, value
);
321 /* only describe this format if it supports OpenGL */
322 if (!value
[0]) continue;
323 /* by default show only fully accelerated window or pbuffer capable visuals */
325 && ((value
[2] && !value
[1])
326 || (!WGLEW_ARB_pbuffer
|| !value
[n_pbuffer
])
327 || (value
[3] != WGL_FULL_ACCELERATION_ARB
))) continue;
328 /* print out the information for this visual */
330 fprintf(file
, " |% 4d | ", i
);
334 if (WGLEW_ARB_pbuffer
&& value
[n_pbuffer
]) fprintf(file
, "wp ");
335 else fprintf(file
, "wn ");
339 if (value
[2]) fprintf(file
, "bm ");
340 else if (WGLEW_ARB_pbuffer
&& value
[n_pbuffer
]) fprintf(file
, "pb ");
343 fprintf(file
, "%s ", value
[3] == WGL_FULL_ACCELERATION_ARB
? "fu" :
344 value
[3] == WGL_GENERIC_ACCELERATION_ARB
? "ge" :
345 value
[3] == WGL_NO_ACCELERATION_ARB
? "no" : ". ");
347 fprintf(file
, " %c ", value
[25] ? 'y' : '.');
349 if (WGLEW_NV_float_buffer
&& value
[n_float
]) fprintf(file
, " f ");
350 else if (WGLEW_ATI_pixel_format_float
&& value
[7] == WGL_TYPE_RGBA_FLOAT_ATI
) fprintf(file
, " f ");
351 else if (value
[7] == WGL_TYPE_RGBA_ARB
) fprintf(file
, " i ");
352 else if (value
[7] == WGL_TYPE_COLORINDEX_ARB
) fprintf(file
, " c ");
354 fprintf(file
, " %c ", value
[5] ? 'y' : '.');
356 if (value
[4] == WGL_SWAP_EXCHANGE_ARB
) fprintf(file
, " x ");
357 else if (value
[4] == WGL_SWAP_COPY_ARB
) fprintf(file
, " c ");
358 else if (value
[4] == WGL_SWAP_UNDEFINED_ARB
) fprintf(file
, " . ");
359 else fprintf(file
, " . ");
361 fprintf(file
, " %c ", value
[6] ? 'y' : '.');
364 fprintf(file
, "%2d | ", value
[24]);
366 fprintf(file
, " . | ");
368 if (value
[8]) fprintf(file
, "%3d ", value
[8]);
369 else fprintf(file
, " . ");
371 if (value
[9]) fprintf(file
, "%2d ", value
[9]);
372 else fprintf(file
, " . ");
374 if (value
[10]) fprintf(file
, "%2d ", value
[10]);
375 else fprintf(file
, " . ");
377 if (value
[11]) fprintf(file
, "%2d ", value
[11]);
378 else fprintf(file
, " . ");
380 if (value
[12]) fprintf(file
, "%2d | ", value
[12]);
381 else fprintf(file
, " . | ");
383 if (value
[20]) fprintf(file
, "%2d ", value
[20]);
384 else fprintf(file
, " . ");
386 if (value
[18]) fprintf(file
, "%2d ", value
[18]);
387 else fprintf(file
, " . ");
389 if (value
[19]) fprintf(file
, "%2d | ", value
[19]);
390 else fprintf(file
, " . | ");
392 if (value
[13]) fprintf(file
, "%3d ", value
[13]);
393 else fprintf(file
, " . ");
395 if (value
[14]) fprintf(file
, "%2d ", value
[14]);
396 else fprintf(file
, " . ");
398 if (value
[15]) fprintf(file
, "%2d ", value
[15]);
399 else fprintf(file
, " . ");
401 if (value
[16]) fprintf(file
, "%2d ", value
[16]);
402 else fprintf(file
, " . ");
404 if (value
[17]) fprintf(file
, "%2d | ", value
[17]);
405 else fprintf(file
, " . | ");
407 if (value
[21]) fprintf(file
, "%2d ", value
[21]);
408 else fprintf(file
, " . ");
410 if (value
[22]) fprintf(file
, "%2d ", value
[22]);
411 else fprintf(file
, " . ");
413 if (value
[23]) fprintf(file
, "y ");
414 else fprintf(file
, " . ");
415 fprintf(file
, "|\n");
417 /* print table footer */
418 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
419 fprintf(file
, " | | visual | color | ax dp st | accum | layer |\n");
420 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");
421 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
427 /* loop through all the pixel formats */
428 for(i
= 1; i
<= maxpf
; i
++)
430 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
431 /* only describe this format if it supports OpenGL */
432 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
433 || (drawableonly
&& !(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
))) continue;
434 fprintf(file
, "Visual ID: %2d depth=%d class=%s\n", i
, pfd
.cDepthBits
,
435 pfd
.cColorBits
<= 8 ? "PseudoColor" : "TrueColor");
436 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
);
437 fprintf(file
, " generic=%d generic accelerated=%d\n", (pfd
.dwFlags
& PFD_GENERIC_FORMAT
) == PFD_GENERIC_FORMAT
, (pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
) == PFD_GENERIC_ACCELERATED
);
438 fprintf(file
, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cRedBits
, pfd
.cGreenBits
, pfd
.cBlueBits
, pfd
.cAlphaBits
);
439 fprintf(file
, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd
.cAuxBuffers
, pfd
.cDepthBits
, pfd
.cStencilBits
);
440 fprintf(file
, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cAccumRedBits
, pfd
.cAccumGreenBits
, pfd
.cAccumBlueBits
, pfd
.cAccumAlphaBits
);
441 fprintf(file
, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
442 fprintf(file
, " Opaque.\n");
449 VisualInfoGDI (GLContext
* ctx
)
452 PIXELFORMATDESCRIPTOR pfd
;
454 /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
455 number of pixel formats */
456 maxpf
= DescribePixelFormat(ctx
->dc
, 1, 0, NULL
);
460 fprintf(file
, "-----------------------------------------------------------------------------\n");
461 fprintf(file
, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
462 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");
463 fprintf(file
, "-----------------------------------------------------------------------------\n");
465 /* loop through all the pixel formats */
466 for(i
= 1; i
<= maxpf
; i
++)
468 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
469 /* only describe this format if it supports OpenGL */
470 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
471 || (drawableonly
&& (pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
))) continue;
472 /* other criteria could be tested here for actual pixel format
473 choosing in an application:
475 for (...each pixel format...) {
476 if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
477 pfd.dwFlags & PFD_DOUBLEBUFFER &&
478 pfd.cDepthBits >= 24 &&
479 pfd.cColorBits >= 24)
484 ... not found so exit ...
486 ... found so use it ...
488 /* print out the information for this pixel format */
489 fprintf(file
, "0x%02x ", i
);
490 fprintf(file
, "%3d ", pfd
.cColorBits
);
491 if(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
) fprintf(file
, "wn ");
492 else if(pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) fprintf(file
, "bm ");
493 else fprintf(file
, "pb ");
494 /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
495 fprintf(file
, " . ");
496 fprintf(file
, "%3d ", pfd
.cColorBits
);
497 /* bReserved field indicates number of over/underlays */
498 if(pfd
.bReserved
) fprintf(file
, " %d ", pfd
.bReserved
);
499 else fprintf(file
, " . ");
500 fprintf(file
, " %c ", pfd
.iPixelType
== PFD_TYPE_RGBA
? 'r' : 'c');
501 fprintf(file
, "%c ", pfd
.dwFlags
& PFD_DOUBLEBUFFER
? 'y' : '.');
502 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_STEREO
? 'y' : '.');
504 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_GENERIC_FORMAT
? 'y' : '.');
505 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
? 'y' : '.');
506 if(pfd
.cRedBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
507 fprintf(file
, "%2d ", pfd
.cRedBits
);
508 else fprintf(file
, " . ");
509 if(pfd
.cGreenBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
510 fprintf(file
, "%2d ", pfd
.cGreenBits
);
511 else fprintf(file
, " . ");
512 if(pfd
.cBlueBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
513 fprintf(file
, "%2d ", pfd
.cBlueBits
);
514 else fprintf(file
, " . ");
515 if(pfd
.cAlphaBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
516 fprintf(file
, "%2d ", pfd
.cAlphaBits
);
517 else fprintf(file
, " . ");
518 if(pfd
.cAuxBuffers
) fprintf(file
, "%2d ", pfd
.cAuxBuffers
);
519 else fprintf(file
, " . ");
520 if(pfd
.cDepthBits
) fprintf(file
, "%2d ", pfd
.cDepthBits
);
521 else fprintf(file
, " . ");
522 if(pfd
.cStencilBits
) fprintf(file
, "%2d ", pfd
.cStencilBits
);
523 else fprintf(file
, " . ");
524 if(pfd
.cAccumBits
) fprintf(file
, "%3d ", pfd
.cAccumBits
);
525 else fprintf(file
, " . ");
526 if(pfd
.cAccumRedBits
) fprintf(file
, "%2d ", pfd
.cAccumRedBits
);
527 else fprintf(file
, " . ");
528 if(pfd
.cAccumGreenBits
) fprintf(file
, "%2d ", pfd
.cAccumGreenBits
);
529 else fprintf(file
, " . ");
530 if(pfd
.cAccumBlueBits
) fprintf(file
, "%2d ", pfd
.cAccumBlueBits
);
531 else fprintf(file
, " . ");
532 if(pfd
.cAccumAlphaBits
) fprintf(file
, "%2d ", pfd
.cAccumAlphaBits
);
533 else fprintf(file
, " . ");
534 /* no multisample in win32 */
535 fprintf(file
, " . .\n");
537 /* print table footer */
538 fprintf(file
, "-----------------------------------------------------------------------------\n");
539 fprintf(file
, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
540 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");
541 fprintf(file
, "-----------------------------------------------------------------------------\n");
546 /* loop through all the pixel formats */
547 for(i
= 1; i
<= maxpf
; i
++)
549 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
550 /* only describe this format if it supports OpenGL */
551 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
552 || (drawableonly
&& !(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
))) continue;
553 fprintf(file
, "Visual ID: %2d depth=%d class=%s\n", i
, pfd
.cDepthBits
,
554 pfd
.cColorBits
<= 8 ? "PseudoColor" : "TrueColor");
555 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
);
556 fprintf(file
, " generic=%d generic accelerated=%d\n", (pfd
.dwFlags
& PFD_GENERIC_FORMAT
) == PFD_GENERIC_FORMAT
, (pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
) == PFD_GENERIC_ACCELERATED
);
557 fprintf(file
, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cRedBits
, pfd
.cGreenBits
, pfd
.cBlueBits
, pfd
.cAlphaBits
);
558 fprintf(file
, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd
.cAuxBuffers
, pfd
.cDepthBits
, pfd
.cStencilBits
);
559 fprintf(file
, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cAccumRedBits
, pfd
.cAccumGreenBits
, pfd
.cAccumBlueBits
, pfd
.cAccumAlphaBits
);
560 fprintf(file
, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
561 fprintf(file
, " Opaque.\n");
567 VisualInfo (GLContext
* ctx
)
569 if (WGLEW_ARB_pixel_format
)
575 /* ---------------------------------------------------------------------- */
577 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
580 VisualInfo (GLContext
* ctx
)
583 int attrib[] = { AGL_RGBA, AGL_NONE };
586 pf = aglChoosePixelFormat(NULL, 0, attrib);
589 aglDescribePixelFormat(pf, GL_RGBA, &value);
590 fprintf(stderr, "%d\n", value);
591 pf = aglNextPixelFormat(pf);
599 VisualInfo (GLContext
* ctx
)
605 fbc
= glXGetFBConfigs(ctx
->dpy
, DefaultScreen(ctx
->dpy
), &n_fbc
);
611 /* print table header */
612 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
613 fprintf(file
, " | | visual | color | ax dp st | accum | ms | cav |\n");
614 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");
615 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
616 /* loop through all the fbcs */
617 for (i
=0; i
<n_fbc
; i
++)
619 /* print out the information for this fbc */
621 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_FBCONFIG_ID
, &value
);
624 fprintf(file
, "| ? |");
628 fprintf(file
, " |% 4d | ", value
);
631 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DRAWABLE_TYPE
, &value
);
634 fprintf(file
, " ? ");
638 if (value
& GLX_WINDOW_BIT
)
640 if (value
& GLX_PBUFFER_BIT
)
642 fprintf(file
, "wp ");
646 fprintf(file
, "wn ");
651 if (value
& GLX_PBUFFER_BIT
)
653 fprintf(file
, "pb ");
655 else if (value
& GLX_PIXMAP_BIT
)
657 fprintf(file
, "pm ");
661 fprintf(file
, " ? ");
666 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_X_RENDERABLE
, &value
);
669 fprintf(file
, " ? ");
673 fprintf(file
, value
? " y " : " n ");
676 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_X_VISUAL_TYPE
, &value
);
679 fprintf(file
, " ? ");
683 if (GLX_TRUE_COLOR
== value
)
684 fprintf(file
, "tc ");
685 else if (GLX_DIRECT_COLOR
== value
)
686 fprintf(file
, "dc ");
687 else if (GLX_PSEUDO_COLOR
== value
)
688 fprintf(file
, "pc ");
689 else if (GLX_STATIC_COLOR
== value
)
690 fprintf(file
, "sc ");
691 else if (GLX_GRAY_SCALE
== value
)
692 fprintf(file
, "gs ");
693 else if (GLX_STATIC_GRAY
== value
)
694 fprintf(file
, "sg ");
695 else if (GLX_X_VISUAL_TYPE
== value
)
696 fprintf(file
, " . ");
698 fprintf(file
, " ? ");
701 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_RENDER_TYPE
, &value
);
704 fprintf(file
, " ? ");
708 if (GLXEW_NV_float_buffer
)
711 ret2
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_FLOAT_COMPONENTS_NV
, &value2
);
712 if (Success
== ret2
&& GL_TRUE
== value2
)
714 fprintf(file
, " f ");
716 else if (value
& GLX_RGBA_BIT
)
717 fprintf(file
, " i ");
718 else if (value
& GLX_COLOR_INDEX_BIT
)
719 fprintf(file
, " c ");
721 fprintf(file
, " ? ");
725 if (value
& GLX_RGBA_FLOAT_ATI_BIT
)
726 fprintf(file
, " f ");
727 else if (value
& GLX_RGBA_BIT
)
728 fprintf(file
, " i ");
729 else if (value
& GLX_COLOR_INDEX_BIT
)
730 fprintf(file
, " c ");
732 fprintf(file
, " ? ");
736 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DOUBLEBUFFER
, &value
);
737 fprintf(file
, " %c ", Success
!= ret
? '?' : (value
? 'y' : '.'));
739 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_STEREO
, &value
);
740 fprintf(file
, " %c ", Success
!= ret
? '?' : (value
? 'y' : '.'));
742 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_LEVEL
, &value
);
745 fprintf(file
, " ? ");
749 fprintf(file
, "%2d ", value
);
752 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_TRANSPARENT_TYPE
, &value
);
755 fprintf(file
, " ? | ");
759 if (GLX_TRANSPARENT_RGB
== value
)
760 fprintf(file
, " r | ");
761 else if (GLX_TRANSPARENT_INDEX
== value
)
762 fprintf(file
, " i | ");
763 else if (GLX_NONE
== value
)
764 fprintf(file
, " . | ");
766 fprintf(file
, " ? | ");
769 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_BUFFER_SIZE
, &value
);
772 fprintf(file
, " ? ");
777 fprintf(file
, "%3d ", value
);
779 fprintf(file
, " . ");
782 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_RED_SIZE
, &value
);
785 fprintf(file
, " ? ");
790 fprintf(file
, "%2d ", value
);
792 fprintf(file
, " . ");
795 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_GREEN_SIZE
, &value
);
798 fprintf(file
, " ? ");
803 fprintf(file
, "%2d ", value
);
805 fprintf(file
, " . ");
808 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_BLUE_SIZE
, &value
);
811 fprintf(file
, " ? ");
816 fprintf(file
, "%2d ", value
);
818 fprintf(file
, " . ");
821 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ALPHA_SIZE
, &value
);
824 fprintf(file
, " ? | ");
829 fprintf(file
, "%2d | ", value
);
831 fprintf(file
, " . | ");
834 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_AUX_BUFFERS
, &value
);
837 fprintf(file
, " ? ");
842 fprintf(file
, "%2d ", value
);
844 fprintf(file
, " . ");
847 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DEPTH_SIZE
, &value
);
850 fprintf(file
, " ? ");
855 fprintf(file
, "%2d ", value
);
857 fprintf(file
, " . ");
860 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_STENCIL_SIZE
, &value
);
863 fprintf(file
, " ? | ");
868 fprintf(file
, "%2d | ", value
);
870 fprintf(file
, " . | ");
873 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_RED_SIZE
, &value
);
876 fprintf(file
, " ? ");
881 fprintf(file
, "%2d ", value
);
883 fprintf(file
, " . ");
885 /* accum green size */
886 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_GREEN_SIZE
, &value
);
889 fprintf(file
, " ? ");
894 fprintf(file
, "%2d ", value
);
896 fprintf(file
, " . ");
898 /* accum blue size */
899 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_BLUE_SIZE
, &value
);
902 fprintf(file
, " ? ");
907 fprintf(file
, "%2d ", value
);
909 fprintf(file
, " . ");
911 /* accum alpha size */
912 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_ALPHA_SIZE
, &value
);
915 fprintf(file
, " ? | ");
920 fprintf(file
, "%2d | ", value
);
922 fprintf(file
, " . | ");
925 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_SAMPLES
, &value
);
928 fprintf(file
, " ? ");
932 fprintf(file
, "%2d ", value
);
934 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_SAMPLE_BUFFERS
, &value
);
937 fprintf(file
, " ? | ");
941 fprintf(file
, "%2d | ", value
);
944 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_CONFIG_CAVEAT
, &value
);
947 fprintf(file
, "???? |");
951 if (GLX_NONE
== value
)
952 fprintf(file
, "none |\n");
953 else if (GLX_SLOW_CONFIG
== value
)
954 fprintf(file
, "slow |\n");
955 else if (GLX_NON_CONFORMANT_CONFIG
== value
)
956 fprintf(file
, "ncft |\n");
958 fprintf(file
, "???? |\n");
961 /* print table footer */
962 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
963 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");
964 fprintf(file
, " | | visual | color | ax dp st | accum | ms | cav |\n");
965 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
972 /* ------------------------------------------------------------------------ */
976 void InitContext (GLContext
* ctx
)
983 GLboolean
CreateContext (GLContext
* ctx
)
986 PIXELFORMATDESCRIPTOR pfd
;
987 /* check for input */
988 if (NULL
== ctx
) return GL_TRUE
;
989 /* register window class */
990 ZeroMemory(&wc
, sizeof(WNDCLASS
));
991 wc
.hInstance
= GetModuleHandle(NULL
);
992 wc
.lpfnWndProc
= DefWindowProc
;
993 wc
.lpszClassName
= "GLEW";
994 if (0 == RegisterClass(&wc
)) return GL_TRUE
;
996 ctx
->wnd
= CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT
, CW_USEDEFAULT
,
997 CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
,
998 GetModuleHandle(NULL
), NULL
);
999 if (NULL
== ctx
->wnd
) return GL_TRUE
;
1000 /* get the device context */
1001 ctx
->dc
= GetDC(ctx
->wnd
);
1002 if (NULL
== ctx
->dc
) return GL_TRUE
;
1003 /* find pixel format */
1004 ZeroMemory(&pfd
, sizeof(PIXELFORMATDESCRIPTOR
));
1005 if (visual
== -1) /* find default */
1007 pfd
.nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1009 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1010 visual
= ChoosePixelFormat(ctx
->dc
, &pfd
);
1011 if (0 == visual
) return GL_TRUE
;
1013 /* set the pixel format for the dc */
1014 if (FALSE
== SetPixelFormat(ctx
->dc
, visual
, &pfd
)) return GL_TRUE
;
1015 /* create rendering context */
1016 ctx
->rc
= wglCreateContext(ctx
->dc
);
1017 if (NULL
== ctx
->rc
) return GL_TRUE
;
1018 if (FALSE
== wglMakeCurrent(ctx
->dc
, ctx
->rc
)) return GL_TRUE
;
1022 void DestroyContext (GLContext
* ctx
)
1024 if (NULL
== ctx
) return;
1025 if (NULL
!= ctx
->rc
) wglMakeCurrent(NULL
, NULL
);
1026 if (NULL
!= ctx
->rc
) wglDeleteContext(wglGetCurrentContext());
1027 if (NULL
!= ctx
->wnd
&& NULL
!= ctx
->dc
) ReleaseDC(ctx
->wnd
, ctx
->dc
);
1028 if (NULL
!= ctx
->wnd
) DestroyWindow(ctx
->wnd
);
1029 UnregisterClass("GLEW", GetModuleHandle(NULL
));
1032 /* ------------------------------------------------------------------------ */
1034 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
1036 void InitContext (GLContext
* ctx
)
1042 GLboolean
CreateContext (GLContext
* ctx
)
1044 int attrib
[] = { AGL_RGBA
, AGL_NONE
};
1047 if (NULL
== ctx
) return GL_TRUE
;
1049 SetPortWindowPort(wnd);
1050 aglGetVersion(&major, &minor);
1051 fprintf(stderr, "GL %d.%d\n", major, minor);*/
1052 pf
= aglChoosePixelFormat(NULL
, 0, attrib
);
1053 if (NULL
== pf
) return GL_TRUE
;
1054 ctx
->ctx
= aglCreateContext(pf
, NULL
);
1055 if (NULL
== ctx
->ctx
|| AGL_NO_ERROR
!= aglGetError()) return GL_TRUE
;
1056 aglDestroyPixelFormat(pf
);
1057 /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
1058 ctx
->octx
= aglGetCurrentContext();
1059 if (GL_FALSE
== aglSetCurrentContext(ctx
->ctx
)) return GL_TRUE
;
1063 void DestroyContext (GLContext
* ctx
)
1065 if (NULL
== ctx
) return;
1066 aglSetCurrentContext(ctx
->octx
);
1067 if (NULL
!= ctx
->ctx
) aglDestroyContext(ctx
->ctx
);
1070 /* ------------------------------------------------------------------------ */
1072 #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1074 void InitContext (GLContext
* ctx
)
1083 GLboolean
CreateContext (GLContext
* ctx
)
1085 int attrib
[] = { GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
1087 XSetWindowAttributes swa
;
1089 if (NULL
== ctx
) return GL_TRUE
;
1091 ctx
->dpy
= XOpenDisplay(display
);
1092 if (NULL
== ctx
->dpy
) return GL_TRUE
;
1094 if (!glXQueryExtension(ctx
->dpy
, &erb
, &evb
)) return GL_TRUE
;
1096 ctx
->vi
= glXChooseVisual(ctx
->dpy
, DefaultScreen(ctx
->dpy
), attrib
);
1097 if (NULL
== ctx
->vi
) return GL_TRUE
;
1098 /* create context */
1099 ctx
->ctx
= glXCreateContext(ctx
->dpy
, ctx
->vi
, None
, True
);
1100 if (NULL
== ctx
->ctx
) return GL_TRUE
;
1102 /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
1103 ctx
->cmap
= XCreateColormap(ctx
->dpy
, RootWindow(ctx
->dpy
, ctx
->vi
->screen
),
1104 ctx
->vi
->visual
, AllocNone
);
1105 swa
.border_pixel
= 0;
1106 swa
.colormap
= ctx
->cmap
;
1107 ctx
->wnd
= XCreateWindow(ctx
->dpy
, RootWindow(ctx
->dpy
, ctx
->vi
->screen
),
1108 0, 0, 1, 1, 0, ctx
->vi
->depth
, InputOutput
, ctx
->vi
->visual
,
1109 CWBorderPixel
| CWColormap
, &swa
);
1110 /* make context current */
1111 if (!glXMakeCurrent(ctx
->dpy
, ctx
->wnd
, ctx
->ctx
)) return GL_TRUE
;
1115 void DestroyContext (GLContext
* ctx
)
1117 if (NULL
!= ctx
->dpy
&& NULL
!= ctx
->ctx
) glXDestroyContext(ctx
->dpy
, ctx
->ctx
);
1118 if (NULL
!= ctx
->dpy
&& 0 != ctx
->wnd
) XDestroyWindow(ctx
->dpy
, ctx
->wnd
);
1119 if (NULL
!= ctx
->dpy
&& 0 != ctx
->cmap
) XFreeColormap(ctx
->dpy
, ctx
->cmap
);
1120 if (NULL
!= ctx
->vi
) XFree(ctx
->vi
);
1121 if (NULL
!= ctx
->dpy
) XCloseDisplay(ctx
->dpy
);
1124 #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1126 GLboolean
ParseArgs (int argc
, char** argv
)
1132 if (!strcmp(argv
[p
], "-pf") || !strcmp(argv
[p
], "-pixelformat"))
1134 if (++p
>= argc
) return GL_TRUE
;
1136 visual
= strtol(argv
[p
], NULL
, 0);
1138 else if (!strcmp(argv
[p
], "-a"))
1142 else if (!strcmp(argv
[p
], "-s"))
1146 else if (!strcmp(argv
[p
], "-h"))
1153 if (!strcmp(argv
[p
], "-display"))
1155 if (++p
>= argc
) return GL_TRUE
;
1158 else if (!strcmp(argv
[p
], "-visual"))
1160 if (++p
>= argc
) return GL_TRUE
;
1161 visual
= (int)strtol(argv
[p
], NULL
, 0);
1163 else if (!strcmp(argv
[p
], "-h"))