kusano 7d535a
/*
kusano 7d535a
** visualinfo.c
kusano 7d535a
**
kusano 7d535a
** Copyright (C) Nate Robins, 1997
kusano 7d535a
**               Michael Wimmer, 1999
kusano 7d535a
**               Milan Ikits, 2002-2008
kusano 7d535a
**
kusano 7d535a
** visualinfo is a small utility that displays all available visuals,
kusano 7d535a
** aka. pixelformats, in an OpenGL system along with renderer version
kusano 7d535a
** information. It shows a table of all the visuals that support OpenGL
kusano 7d535a
** along with their capabilities. The format of the table is similar to
kusano 7d535a
** that of glxinfo on Unix systems:
kusano 7d535a
**
kusano 7d535a
** visual ~= pixel format descriptor
kusano 7d535a
** id       = visual id (integer from 1 - max visuals)
kusano 7d535a
** tp       = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)
kusano 7d535a
** ac	    = acceleration (ge: generic, fu: full, no: none)
kusano 7d535a
** fm	    = format (i: integer, f: float, c: color index)
kusano 7d535a
** db	    = double buffer (y = yes)
kusano 7d535a
** sw       = swap method (x: exchange, c: copy, u: undefined)
kusano 7d535a
** st	    = stereo (y = yes)
kusano 7d535a
** sz       = total # bits
kusano 7d535a
** r        = # bits of red
kusano 7d535a
** g        = # bits of green
kusano 7d535a
** b        = # bits of blue
kusano 7d535a
** a        = # bits of alpha
kusano 7d535a
** axbf     = # aux buffers
kusano 7d535a
** dpth     = # bits of depth
kusano 7d535a
** stcl     = # bits of stencil
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#include <stdio.h></stdio.h>
kusano 7d535a
#include <stdlib.h></stdlib.h>
kusano 7d535a
#include <string.h></string.h>
kusano 7d535a
#include <gl glew.h=""></gl>
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
#include <gl wglew.h=""></gl>
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
#include <agl agl.h=""></agl>
kusano 7d535a
#else
kusano 7d535a
#include <gl glxew.h=""></gl>
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifdef GLEW_MX
kusano 7d535a
GLEWContext _glewctx;
kusano 7d535a
#  define glewGetContext() (&_glewctx)
kusano 7d535a
#  ifdef _WIN32
kusano 7d535a
WGLEWContext _wglewctx;
kusano 7d535a
#    define wglewGetContext() (&_wglewctx)
kusano 7d535a
#  elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
GLXEWContext _glxewctx;
kusano 7d535a
#    define glxewGetContext() (&_glxewctx)
kusano 7d535a
#  endif
kusano 7d535a
#endif /* GLEW_MX */
kusano 7d535a
kusano 7d535a
typedef struct GLContextStruct
kusano 7d535a
{
kusano 7d535a
#ifdef _WIN32
kusano 7d535a
  HWND wnd;
kusano 7d535a
  HDC dc;
kusano 7d535a
  HGLRC rc;
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
  AGLContext ctx, octx;
kusano 7d535a
#else
kusano 7d535a
  Display* dpy;
kusano 7d535a
  XVisualInfo* vi;
kusano 7d535a
  GLXContext ctx;
kusano 7d535a
  Window wnd;
kusano 7d535a
  Colormap cmap;
kusano 7d535a
#endif
kusano 7d535a
} GLContext;
kusano 7d535a
kusano 7d535a
void InitContext (GLContext* ctx);
kusano 7d535a
GLboolean CreateContext (GLContext* ctx);
kusano 7d535a
void DestroyContext (GLContext* ctx);
kusano 7d535a
void VisualInfo (GLContext* ctx);
kusano 7d535a
void PrintExtensions (const char* s);
kusano 7d535a
GLboolean ParseArgs (int argc, char** argv);
kusano 7d535a
kusano 7d535a
int showall = 0;
kusano 7d535a
int displaystdout = 0;
kusano 7d535a
int verbose = 0;
kusano 7d535a
int drawableonly = 0;
kusano 7d535a
kusano 7d535a
char* display = NULL;
kusano 7d535a
int visual = -1;
kusano 7d535a
kusano 7d535a
FILE* file = 0;
kusano 7d535a
kusano 7d535a
int 
kusano 7d535a
main (int argc, char** argv)
kusano 7d535a
{
kusano 7d535a
  GLenum err;
kusano 7d535a
  GLContext ctx;
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* parse arguments */
kusano 7d535a
  if (GL_TRUE == ParseArgs(argc-1, argv+1))
kusano 7d535a
  {
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
    fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");</id>
kusano 7d535a
    fprintf(stderr, "        -a: show all visuals\n");
kusano 7d535a
    fprintf(stderr, "        -s: display to stdout instead of visualinfo.txt\n");
kusano 7d535a
    fprintf(stderr, "        -pf <id>: use given pixelformat\n");</id>
kusano 7d535a
    fprintf(stderr, "        -h: this screen\n");
kusano 7d535a
#else
kusano 7d535a
    fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");</id></display>
kusano 7d535a
    fprintf(stderr, "        -h: this screen\n");
kusano 7d535a
    fprintf(stderr, "        -display <display>: use given display\n");</display>
kusano 7d535a
    fprintf(stderr, "        -visual <id>: use given visual\n");</id>
kusano 7d535a
#endif
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* create OpenGL rendering context */
kusano 7d535a
  InitContext(&ctx);
kusano 7d535a
  if (GL_TRUE == CreateContext(&ctx))
kusano 7d535a
  {
kusano 7d535a
    fprintf(stderr, "Error: CreateContext failed\n");
kusano 7d535a
    DestroyContext(&ctx);
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* initialize GLEW */
kusano 7d535a
  glewExperimental = GL_TRUE;
kusano 7d535a
#ifdef GLEW_MX
kusano 7d535a
  err = glewContextInit(glewGetContext());
kusano 7d535a
#  ifdef _WIN32
kusano 7d535a
  err = err || wglewContextInit(wglewGetContext());
kusano 7d535a
#  elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
  err = err || glxewContextInit(glxewGetContext());
kusano 7d535a
#  endif
kusano 7d535a
#else
kusano 7d535a
  err = glewInit();
kusano 7d535a
#endif
kusano 7d535a
  if (GLEW_OK != err)
kusano 7d535a
  {
kusano 7d535a
    fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
kusano 7d535a
    DestroyContext(&ctx);
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* open file */
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  if (!displaystdout) 
kusano 7d535a
    file = fopen("visualinfo.txt", "w");
kusano 7d535a
  if (file == NULL)
kusano 7d535a
    file = stdout;
kusano 7d535a
#else
kusano 7d535a
  file = stdout;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* output header information */
kusano 7d535a
  /* OpenGL extensions */
kusano 7d535a
  fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR));
kusano 7d535a
  fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER));
kusano 7d535a
  fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION));
kusano 7d535a
  fprintf(file, "OpenGL extensions (GL_): \n");
kusano 7d535a
  PrintExtensions((char*)glGetString(GL_EXTENSIONS));
kusano 7d535a
kusano 7d535a
#ifndef GLEW_NO_GLU
kusano 7d535a
  /* GLU extensions */
kusano 7d535a
  fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION));
kusano 7d535a
  fprintf(file, "GLU extensions (GLU_): \n");
kusano 7d535a
  PrintExtensions((char*)gluGetString(GLU_EXTENSIONS));
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* extensions string */
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  /* WGL extensions */
kusano 7d535a
  if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)
kusano 7d535a
  {
kusano 7d535a
    fprintf(file, "WGL extensions (WGL_): \n");
kusano 7d535a
    PrintExtensions(wglGetExtensionsStringARB ? 
kusano 7d535a
                    (char*)wglGetExtensionsStringARB(ctx.dc) :
kusano 7d535a
		    (char*)wglGetExtensionsStringEXT());
kusano 7d535a
  }
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
  
kusano 7d535a
#else
kusano 7d535a
  /* GLX extensions */
kusano 7d535a
  fprintf(file, "GLX extensions (GLX_): \n");
kusano 7d535a
  PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(), 
kusano 7d535a
                                           DefaultScreen(glXGetCurrentDisplay())));
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* enumerate all the formats */
kusano 7d535a
  VisualInfo(&ctx);
kusano 7d535a
kusano 7d535a
  /* ---------------------------------------------------------------------- */
kusano 7d535a
  /* release resources */
kusano 7d535a
  DestroyContext(&ctx);
kusano 7d535a
  if (file != stdout)
kusano 7d535a
    fclose(file);
kusano 7d535a
  return 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* do the magic to separate all extensions with comma's, except
kusano 7d535a
   for the last one that _may_ terminate in a space. */
kusano 7d535a
void PrintExtensions (const char* s)
kusano 7d535a
{
kusano 7d535a
  char t[80];
kusano 7d535a
  int i=0;
kusano 7d535a
  char* p=0;
kusano 7d535a
kusano 7d535a
  t[79] = '\0';
kusano 7d535a
  while (*s)
kusano 7d535a
  {
kusano 7d535a
    t[i++] = *s;
kusano 7d535a
    if(*s == ' ')
kusano 7d535a
    {
kusano 7d535a
      if (*(s+1) != '\0') {
kusano 7d535a
	t[i-1] = ',';
kusano 7d535a
	t[i] = ' ';
kusano 7d535a
	p = &t[i++];
kusano 7d535a
      }
kusano 7d535a
      else /* zoinks! last one terminated in a space! */
kusano 7d535a
      {
kusano 7d535a
	t[i-1] = '\0';
kusano 7d535a
      }
kusano 7d535a
    }
kusano 7d535a
    if(i > 80 - 5)
kusano 7d535a
    {
kusano 7d535a
      *p = t[i] = '\0';
kusano 7d535a
      fprintf(file, "    %s\n", t);
kusano 7d535a
      p++;
kusano 7d535a
      i = (int)strlen(p);
kusano 7d535a
      strcpy(t, p);
kusano 7d535a
    }
kusano 7d535a
    s++;
kusano 7d535a
  }
kusano 7d535a
  t[i] = '\0';
kusano 7d535a
  fprintf(file, "    %s.\n", t);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ---------------------------------------------------------------------- */
kusano 7d535a
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
kusano 7d535a
void
kusano 7d535a
VisualInfoARB (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;
kusano 7d535a
  int i, pf, maxpf;
kusano 7d535a
  unsigned int c;
kusano 7d535a
kusano 7d535a
  /* to get pbuffer capable pixel formats */
kusano 7d535a
  attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;
kusano 7d535a
  attrib[1] = GL_TRUE;
kusano 7d535a
  attrib[2] = 0;
kusano 7d535a
  wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);
kusano 7d535a
  /* query number of pixel formats */
kusano 7d535a
  attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
kusano 7d535a
  wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);
kusano 7d535a
  maxpf = value[0];
kusano 7d535a
  for (i=0; i<32; i++)
kusano 7d535a
    value[i] = 0;
kusano 7d535a
kusano 7d535a
  attrib[0] = WGL_SUPPORT_OPENGL_ARB;
kusano 7d535a
  attrib[1] = WGL_DRAW_TO_WINDOW_ARB;
kusano 7d535a
  attrib[2] = WGL_DRAW_TO_BITMAP_ARB;
kusano 7d535a
  attrib[3] = WGL_ACCELERATION_ARB;
kusano 7d535a
  /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
kusano 7d535a
  attrib[4] = WGL_SWAP_METHOD_ARB;
kusano 7d535a
  /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
kusano 7d535a
  attrib[5] = WGL_DOUBLE_BUFFER_ARB;
kusano 7d535a
  attrib[6] = WGL_STEREO_ARB;
kusano 7d535a
  attrib[7] = WGL_PIXEL_TYPE_ARB;
kusano 7d535a
  /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
kusano 7d535a
     WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
kusano 7d535a
  /* Color buffer information */
kusano 7d535a
  attrib[8] = WGL_COLOR_BITS_ARB;
kusano 7d535a
  attrib[9] = WGL_RED_BITS_ARB;
kusano 7d535a
  attrib[10] = WGL_GREEN_BITS_ARB;
kusano 7d535a
  attrib[11] = WGL_BLUE_BITS_ARB;
kusano 7d535a
  attrib[12] = WGL_ALPHA_BITS_ARB;
kusano 7d535a
  /* Accumulation buffer information */
kusano 7d535a
  attrib[13] = WGL_ACCUM_BITS_ARB;
kusano 7d535a
  attrib[14] = WGL_ACCUM_RED_BITS_ARB;
kusano 7d535a
  attrib[15] = WGL_ACCUM_GREEN_BITS_ARB;
kusano 7d535a
  attrib[16] = WGL_ACCUM_BLUE_BITS_ARB;
kusano 7d535a
  attrib[17] = WGL_ACCUM_ALPHA_BITS_ARB;
kusano 7d535a
  /* Depth, stencil, and aux buffer information */
kusano 7d535a
  attrib[18] = WGL_DEPTH_BITS_ARB;
kusano 7d535a
  attrib[19] = WGL_STENCIL_BITS_ARB;
kusano 7d535a
  attrib[20] = WGL_AUX_BUFFERS_ARB;
kusano 7d535a
  /* Layer information */
kusano 7d535a
  attrib[21] = WGL_NUMBER_OVERLAYS_ARB;
kusano 7d535a
  attrib[22] = WGL_NUMBER_UNDERLAYS_ARB;
kusano 7d535a
  attrib[23] = WGL_SWAP_LAYER_BUFFERS_ARB;
kusano 7d535a
  attrib[24] = WGL_SAMPLES_ARB;
kusano 7d535a
  attrib[25] = WGL_SUPPORT_GDI_ARB;
kusano 7d535a
  n_attrib = 26;
kusano 7d535a
  if (WGLEW_ARB_pbuffer)
kusano 7d535a
  {
kusano 7d535a
    attrib[n_attrib] = WGL_DRAW_TO_PBUFFER_ARB;
kusano 7d535a
    n_pbuffer = n_attrib;
kusano 7d535a
    n_attrib++;
kusano 7d535a
  }
kusano 7d535a
  if (WGLEW_NV_float_buffer)
kusano 7d535a
  {
kusano 7d535a
    attrib[n_attrib] = WGL_FLOAT_COMPONENTS_NV;
kusano 7d535a
    n_float = n_attrib;
kusano 7d535a
    n_attrib++;
kusano 7d535a
  }
kusano 7d535a
  
kusano 7d535a
  if (!verbose)
kusano 7d535a
  {
kusano 7d535a
    /* print table header */
kusano 7d535a
    fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
kusano 7d535a
    fprintf(file, " |     |          visual         |      color      | ax dp st |      accum      |   layer  |\n");
kusano 7d535a
    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");
kusano 7d535a
    fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
kusano 7d535a
    /* loop through all the pixel formats */
kusano 7d535a
    for(i = 1; i <= maxpf; i++)
kusano 7d535a
    {
kusano 7d535a
      wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);
kusano 7d535a
      /* only describe this format if it supports OpenGL */
kusano 7d535a
      if (!value[0]) continue;
kusano 7d535a
      /* by default show only fully accelerated window or pbuffer capable visuals */
kusano 7d535a
      if (!showall
kusano 7d535a
	  && ((value[2] && !value[1])
kusano 7d535a
	  || (!WGLEW_ARB_pbuffer || !value[n_pbuffer])
kusano 7d535a
	  || (value[3] != WGL_FULL_ACCELERATION_ARB))) continue;
kusano 7d535a
      /* print out the information for this visual */
kusano 7d535a
      /* visual id */
kusano 7d535a
      fprintf(file, " |% 4d | ", i);
kusano 7d535a
      /* visual type */
kusano 7d535a
      if (value[1])
kusano 7d535a
      {
kusano 7d535a
	if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "wp ");
kusano 7d535a
	else fprintf(file, "wn ");
kusano 7d535a
      }
kusano 7d535a
      else
kusano 7d535a
      {
kusano 7d535a
	if (value[2]) fprintf(file, "bm ");
kusano 7d535a
	else if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "pb ");
kusano 7d535a
      }
kusano 7d535a
      /* acceleration */
kusano 7d535a
      fprintf(file, "%s ", value[3] == WGL_FULL_ACCELERATION_ARB ? "fu" : 
kusano 7d535a
	      value[3] == WGL_GENERIC_ACCELERATION_ARB ? "ge" :
kusano 7d535a
	      value[3] == WGL_NO_ACCELERATION_ARB ? "no" : ". ");
kusano 7d535a
      /* gdi support */
kusano 7d535a
      fprintf(file, " %c ", value[25] ? 'y' : '.');
kusano 7d535a
      /* format */
kusano 7d535a
      if (WGLEW_NV_float_buffer && value[n_float]) fprintf(file, " f ");
kusano 7d535a
      else if (WGLEW_ATI_pixel_format_float && value[7] == WGL_TYPE_RGBA_FLOAT_ATI) fprintf(file, " f ");
kusano 7d535a
      else if (value[7] == WGL_TYPE_RGBA_ARB) fprintf(file, " i ");
kusano 7d535a
      else if (value[7] == WGL_TYPE_COLORINDEX_ARB) fprintf(file, " c ");
kusano 7d535a
      else if (value[7] == WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT) fprintf(file," p ");
kusano 7d535a
      else fprintf(file," ? ");
kusano 7d535a
      /* double buffer */
kusano 7d535a
      fprintf(file, " %c ", value[5] ? 'y' : '.');
kusano 7d535a
      /* swap method */
kusano 7d535a
      if (value[4] == WGL_SWAP_EXCHANGE_ARB) fprintf(file, " x ");
kusano 7d535a
      else if (value[4] == WGL_SWAP_COPY_ARB) fprintf(file, " c ");
kusano 7d535a
      else if (value[4] == WGL_SWAP_UNDEFINED_ARB) fprintf(file, " . ");
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* stereo */
kusano 7d535a
      fprintf(file, " %c ", value[6] ? 'y' : '.');
kusano 7d535a
      /* multisample */
kusano 7d535a
      if (value[24] > 0)
kusano 7d535a
	fprintf(file, "%2d | ", value[24]);
kusano 7d535a
      else
kusano 7d535a
	fprintf(file, " . | ");
kusano 7d535a
      /* color size */
kusano 7d535a
      if (value[8]) fprintf(file, "%3d ", value[8]);
kusano 7d535a
      else fprintf(file, "  . ");
kusano 7d535a
      /* red */
kusano 7d535a
      if (value[9]) fprintf(file, "%2d ", value[9]); 
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* green */
kusano 7d535a
      if (value[10]) fprintf(file, "%2d ", value[10]); 
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* blue */
kusano 7d535a
      if (value[11]) fprintf(file, "%2d ", value[11]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* alpha */
kusano 7d535a
      if (value[12]) fprintf(file, "%2d | ", value[12]); 
kusano 7d535a
      else fprintf(file, " . | ");
kusano 7d535a
      /* aux buffers */
kusano 7d535a
      if (value[20]) fprintf(file, "%2d ", value[20]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* depth */
kusano 7d535a
      if (value[18]) fprintf(file, "%2d ", value[18]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* stencil */
kusano 7d535a
      if (value[19]) fprintf(file, "%2d | ", value[19]);
kusano 7d535a
      else fprintf(file, " . | ");
kusano 7d535a
      /* accum size */
kusano 7d535a
      if (value[13]) fprintf(file, "%3d ", value[13]);
kusano 7d535a
      else fprintf(file, "  . ");
kusano 7d535a
      /* accum red */
kusano 7d535a
      if (value[14]) fprintf(file, "%2d ", value[14]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* accum green */
kusano 7d535a
      if (value[15]) fprintf(file, "%2d ", value[15]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* accum blue */
kusano 7d535a
      if (value[16]) fprintf(file, "%2d ", value[16]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* accum alpha */
kusano 7d535a
      if (value[17]) fprintf(file, "%2d | ", value[17]);
kusano 7d535a
      else fprintf(file, " . | ");
kusano 7d535a
      /* overlay */
kusano 7d535a
      if (value[21]) fprintf(file, "%2d ", value[21]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* underlay */
kusano 7d535a
      if (value[22]) fprintf(file, "%2d ", value[22]);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* layer swap */
kusano 7d535a
      if (value[23]) fprintf(file, "y ");
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      fprintf(file, "|\n");
kusano 7d535a
    }
kusano 7d535a
    /* print table footer */
kusano 7d535a
    fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
kusano 7d535a
    fprintf(file, " |     |          visual         |      color      | ax dp st |      accum      |   layer  |\n");
kusano 7d535a
    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");
kusano 7d535a
    fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
kusano 7d535a
  }
kusano 7d535a
  else /* verbose */
kusano 7d535a
  {
kusano 7d535a
#if 0
kusano 7d535a
    fprintf(file, "\n");
kusano 7d535a
    /* loop through all the pixel formats */
kusano 7d535a
    for(i = 1; i <= maxpf; i++)
kusano 7d535a
    {	    
kusano 7d535a
      DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
kusano 7d535a
      /* only describe this format if it supports OpenGL */
kusano 7d535a
      if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
kusano 7d535a
	 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
kusano 7d535a
      fprintf(file, "Visual ID: %2d  depth=%d  class=%s\n", i, pfd.cDepthBits, 
kusano 7d535a
	     pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
kusano 7d535a
      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);
kusano 7d535a
      fprintf(file, "    generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
kusano 7d535a
      fprintf(file, "    rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
kusano 7d535a
      fprintf(file, "    auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
kusano 7d535a
      fprintf(file, "    accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
kusano 7d535a
      fprintf(file, "    multiSample=%d multisampleBuffers=%d\n", 0, 0);
kusano 7d535a
      fprintf(file, "    Opaque.\n");
kusano 7d535a
    }
kusano 7d535a
#endif
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void
kusano 7d535a
VisualInfoGDI (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  int i, maxpf;
kusano 7d535a
  PIXELFORMATDESCRIPTOR pfd;
kusano 7d535a
kusano 7d535a
  /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
kusano 7d535a
     number of pixel formats */
kusano 7d535a
  maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
kusano 7d535a
kusano 7d535a
  if (!verbose)
kusano 7d535a
  {
kusano 7d535a
    fprintf(file, "-----------------------------------------------------------------------------\n");
kusano 7d535a
    fprintf(file, "   visual   x  bf  lv rg d st ge ge  r  g  b a  ax dp st   accum buffs    ms \n");
kusano 7d535a
    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");
kusano 7d535a
    fprintf(file, "-----------------------------------------------------------------------------\n");
kusano 7d535a
kusano 7d535a
    /* loop through all the pixel formats */
kusano 7d535a
    for(i = 1; i <= maxpf; i++)
kusano 7d535a
    {
kusano 7d535a
      DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
kusano 7d535a
      /* only describe this format if it supports OpenGL */
kusano 7d535a
      if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
kusano 7d535a
	 || (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
kusano 7d535a
      /* other criteria could be tested here for actual pixel format
kusano 7d535a
	 choosing in an application:
kusano 7d535a
	   
kusano 7d535a
	 for (...each pixel format...) {
kusano 7d535a
	 if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
kusano 7d535a
	 pfd.dwFlags & PFD_DOUBLEBUFFER &&
kusano 7d535a
	 pfd.cDepthBits >= 24 &&
kusano 7d535a
	 pfd.cColorBits >= 24)
kusano 7d535a
	 {
kusano 7d535a
	 goto found;
kusano 7d535a
	 }
kusano 7d535a
	 }
kusano 7d535a
	 ... not found so exit ...
kusano 7d535a
	 found:
kusano 7d535a
	 ... found so use it ...
kusano 7d535a
      */
kusano 7d535a
      /* print out the information for this pixel format */
kusano 7d535a
      fprintf(file, "0x%02x ", i);
kusano 7d535a
      fprintf(file, "%3d ", pfd.cColorBits);
kusano 7d535a
      if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");
kusano 7d535a
      else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");
kusano 7d535a
      else fprintf(file, "pb ");
kusano 7d535a
      /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
kusano 7d535a
      fprintf(file, " . "); 
kusano 7d535a
      fprintf(file, "%3d ", pfd.cColorBits);
kusano 7d535a
      /* bReserved field indicates number of over/underlays */
kusano 7d535a
      if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);
kusano 7d535a
      else fprintf(file, " . "); 
kusano 7d535a
      fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
kusano 7d535a
      fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
kusano 7d535a
      fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
kusano 7d535a
      /* added: */
kusano 7d535a
      fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');
kusano 7d535a
      fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');
kusano 7d535a
      if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA) 
kusano 7d535a
	fprintf(file, "%2d ", pfd.cRedBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA) 
kusano 7d535a
	fprintf(file, "%2d ", pfd.cGreenBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA) 
kusano 7d535a
	fprintf(file, "%2d ", pfd.cBlueBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA) 
kusano 7d535a
	fprintf(file, "%2d ", pfd.cAlphaBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAuxBuffers)     fprintf(file, "%2d ", pfd.cAuxBuffers);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cDepthBits)      fprintf(file, "%2d ", pfd.cDepthBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cStencilBits)    fprintf(file, "%2d ", pfd.cStencilBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAccumBits)   fprintf(file, "%3d ", pfd.cAccumBits);
kusano 7d535a
      else fprintf(file, "  . ");
kusano 7d535a
      if(pfd.cAccumRedBits)   fprintf(file, "%2d ", pfd.cAccumRedBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAccumBlueBits)  fprintf(file, "%2d ", pfd.cAccumBlueBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);
kusano 7d535a
      else fprintf(file, " . ");
kusano 7d535a
      /* no multisample in win32 */
kusano 7d535a
      fprintf(file, " . .\n");
kusano 7d535a
    }
kusano 7d535a
    /* print table footer */
kusano 7d535a
    fprintf(file, "-----------------------------------------------------------------------------\n");
kusano 7d535a
    fprintf(file, "   visual   x  bf  lv rg d st ge ge  r  g  b a  ax dp st   accum buffs    ms \n");
kusano 7d535a
    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");
kusano 7d535a
    fprintf(file, "-----------------------------------------------------------------------------\n");
kusano 7d535a
  }
kusano 7d535a
  else /* verbose */
kusano 7d535a
  {
kusano 7d535a
    fprintf(file, "\n");
kusano 7d535a
    /* loop through all the pixel formats */
kusano 7d535a
    for(i = 1; i <= maxpf; i++)
kusano 7d535a
    {	    
kusano 7d535a
      DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
kusano 7d535a
      /* only describe this format if it supports OpenGL */
kusano 7d535a
      if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
kusano 7d535a
	 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
kusano 7d535a
      fprintf(file, "Visual ID: %2d  depth=%d  class=%s\n", i, pfd.cDepthBits, 
kusano 7d535a
	     pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
kusano 7d535a
      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);
kusano 7d535a
      fprintf(file, "    generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
kusano 7d535a
      fprintf(file, "    rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
kusano 7d535a
      fprintf(file, "    auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
kusano 7d535a
      fprintf(file, "    accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
kusano 7d535a
      fprintf(file, "    multiSample=%d multisampleBuffers=%d\n", 0, 0);
kusano 7d535a
      fprintf(file, "    Opaque.\n");
kusano 7d535a
    }
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void
kusano 7d535a
VisualInfo (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  if (WGLEW_ARB_pixel_format)
kusano 7d535a
    VisualInfoARB(ctx);
kusano 7d535a
  else
kusano 7d535a
    VisualInfoGDI(ctx);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ---------------------------------------------------------------------- */
kusano 7d535a
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
kusano 7d535a
void
kusano 7d535a
VisualInfo (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
/*
kusano 7d535a
  int attrib[] = { AGL_RGBA, AGL_NONE };
kusano 7d535a
  AGLPixelFormat pf;
kusano 7d535a
  GLint value;
kusano 7d535a
  pf = aglChoosePixelFormat(NULL, 0, attrib);
kusano 7d535a
  while (pf != NULL)
kusano 7d535a
  {
kusano 7d535a
    aglDescribePixelFormat(pf, GL_RGBA, &value);
kusano 7d535a
    fprintf(stderr, "%d\n", value);
kusano 7d535a
    pf = aglNextPixelFormat(pf);
kusano 7d535a
  }
kusano 7d535a
*/
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#else /* GLX */
kusano 7d535a
kusano 7d535a
void
kusano 7d535a
VisualInfo (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  int n_fbc;
kusano 7d535a
  GLXFBConfig* fbc;
kusano 7d535a
  int value, ret, i;
kusano 7d535a
kusano 7d535a
  fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);
kusano 7d535a
kusano 7d535a
  if (fbc)
kusano 7d535a
  {
kusano 7d535a
    if (!verbose)
kusano 7d535a
    {
kusano 7d535a
      /* print table header */
kusano 7d535a
      fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
kusano 7d535a
      fprintf(file, " |     |        visual           |      color      | ax dp st |    accum    |   ms  |  cav |\n");
kusano 7d535a
      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");
kusano 7d535a
      fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
kusano 7d535a
      /* loop through all the fbcs */
kusano 7d535a
      for (i=0; i
kusano 7d535a
      {
kusano 7d535a
        /* print out the information for this fbc */
kusano 7d535a
        /* visual id */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FBCONFIG_ID, &value);
kusano 7d535a
        if (ret != Success)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "|  ?  |");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " |% 4d | ", value);
kusano 7d535a
        }
kusano 7d535a
        /* visual type */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DRAWABLE_TYPE, &value);
kusano 7d535a
        if (ret != Success)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value & GLX_WINDOW_BIT)
kusano 7d535a
          {
kusano 7d535a
            if (value & GLX_PBUFFER_BIT)
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, "wp ");
kusano 7d535a
            }
kusano 7d535a
            else
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, "wn ");
kusano 7d535a
            }
kusano 7d535a
          }
kusano 7d535a
          else
kusano 7d535a
          {
kusano 7d535a
            if (value & GLX_PBUFFER_BIT)
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, "pb ");
kusano 7d535a
            }
kusano 7d535a
            else if (value & GLX_PIXMAP_BIT)
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, "pm ");
kusano 7d535a
            }
kusano 7d535a
            else
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, " ? ");
kusano 7d535a
            }
kusano 7d535a
          }
kusano 7d535a
        }
kusano 7d535a
        /* x renderable */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_RENDERABLE, &value);
kusano 7d535a
        if (ret != Success)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, value ? " y " : " n ");
kusano 7d535a
        }
kusano 7d535a
        /* class */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_VISUAL_TYPE, &value);
kusano 7d535a
        if (ret != Success)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (GLX_TRUE_COLOR == value)
kusano 7d535a
            fprintf(file, "tc ");
kusano 7d535a
          else if (GLX_DIRECT_COLOR == value)
kusano 7d535a
            fprintf(file, "dc ");
kusano 7d535a
          else if (GLX_PSEUDO_COLOR == value)
kusano 7d535a
            fprintf(file, "pc ");
kusano 7d535a
          else if (GLX_STATIC_COLOR == value)
kusano 7d535a
            fprintf(file, "sc ");
kusano 7d535a
          else if (GLX_GRAY_SCALE == value)
kusano 7d535a
            fprintf(file, "gs ");
kusano 7d535a
          else if (GLX_STATIC_GRAY == value)
kusano 7d535a
            fprintf(file, "sg ");
kusano 7d535a
          else if (GLX_X_VISUAL_TYPE == value)
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        /* format */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RENDER_TYPE, &value);
kusano 7d535a
        if (ret != Success)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (GLXEW_NV_float_buffer)
kusano 7d535a
          {
kusano 7d535a
            int ret2, value2;
kusano 7d535a
            ret2 = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FLOAT_COMPONENTS_NV, &value2);
kusano 7d535a
            if (Success == ret2 && GL_TRUE == value2)
kusano 7d535a
            {
kusano 7d535a
              fprintf(file, " f ");
kusano 7d535a
            }
kusano 7d535a
            else if (value & GLX_RGBA_BIT)
kusano 7d535a
              fprintf(file, " i ");
kusano 7d535a
            else if (value & GLX_COLOR_INDEX_BIT)
kusano 7d535a
              fprintf(file, " c ");
kusano 7d535a
            else
kusano 7d535a
              fprintf(file, " ? ");
kusano 7d535a
          }
kusano 7d535a
          else
kusano 7d535a
          {
kusano 7d535a
            if (value & GLX_RGBA_FLOAT_ATI_BIT)
kusano 7d535a
              fprintf(file, " f ");
kusano 7d535a
            else if (value & GLX_RGBA_BIT)
kusano 7d535a
              fprintf(file, " i ");
kusano 7d535a
            else if (value & GLX_COLOR_INDEX_BIT)
kusano 7d535a
              fprintf(file, " c ");
kusano 7d535a
            else
kusano 7d535a
              fprintf(file, " ? ");
kusano 7d535a
          }
kusano 7d535a
        }
kusano 7d535a
        /* double buffer */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DOUBLEBUFFER, &value);
kusano 7d535a
        fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
kusano 7d535a
        /* stereo */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STEREO, &value);
kusano 7d535a
        fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
kusano 7d535a
        /* level */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_LEVEL, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "%2d ", value);
kusano 7d535a
        }
kusano 7d535a
        /* transparency */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_TRANSPARENT_TYPE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (GLX_TRANSPARENT_RGB == value)
kusano 7d535a
            fprintf(file, " r | ");
kusano 7d535a
          else if (GLX_TRANSPARENT_INDEX == value)
kusano 7d535a
            fprintf(file, " i | ");
kusano 7d535a
          else if (GLX_NONE == value)
kusano 7d535a
            fprintf(file, " . | ");
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        /* color size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BUFFER_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "  ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%3d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, "  . ");
kusano 7d535a
        }
kusano 7d535a
        /* red size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RED_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* green size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_GREEN_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* blue size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BLUE_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* alpha size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ALPHA_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d | ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . | ");
kusano 7d535a
        }
kusano 7d535a
        /* aux buffers */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_AUX_BUFFERS, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* depth size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DEPTH_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* stencil size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STENCIL_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d | ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . | ");
kusano 7d535a
        }
kusano 7d535a
        /* accum red size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_RED_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* accum green size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_GREEN_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* accum blue size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_BLUE_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . ");
kusano 7d535a
        }
kusano 7d535a
        /* accum alpha size */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_ALPHA_SIZE, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (value)
kusano 7d535a
            fprintf(file, "%2d | ", value);
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, " . | ");
kusano 7d535a
        }
kusano 7d535a
        /* multisample */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLES, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "%2d ", value);
kusano 7d535a
        }
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLE_BUFFERS, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, " ? | ");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "%2d | ", value);
kusano 7d535a
        }
kusano 7d535a
        /* caveat */
kusano 7d535a
        ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_CONFIG_CAVEAT, &value);
kusano 7d535a
        if (Success != ret)
kusano 7d535a
        {
kusano 7d535a
          fprintf(file, "???? |");
kusano 7d535a
        }
kusano 7d535a
        else
kusano 7d535a
        {
kusano 7d535a
          if (GLX_NONE == value)
kusano 7d535a
            fprintf(file, "none |\n");
kusano 7d535a
          else if (GLX_SLOW_CONFIG == value)
kusano 7d535a
            fprintf(file, "slow |\n");
kusano 7d535a
          else if (GLX_NON_CONFORMANT_CONFIG == value)
kusano 7d535a
            fprintf(file, "ncft |\n");
kusano 7d535a
          else
kusano 7d535a
            fprintf(file, "???? |\n");
kusano 7d535a
        }
kusano 7d535a
      }
kusano 7d535a
      /* print table footer */
kusano 7d535a
      fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
kusano 7d535a
      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");
kusano 7d535a
      fprintf(file, " |     |        visual           |      color      | ax dp st |    accum    |   ms  |  cav |\n");
kusano 7d535a
      fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
kusano 7d535a
    }
kusano 7d535a
  }
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
kusano 7d535a
void InitContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  ctx->wnd = NULL;
kusano 7d535a
  ctx->dc = NULL;
kusano 7d535a
  ctx->rc = NULL;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
GLboolean CreateContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  WNDCLASS wc;
kusano 7d535a
  PIXELFORMATDESCRIPTOR pfd;
kusano 7d535a
  /* check for input */
kusano 7d535a
  if (NULL == ctx) return GL_TRUE;
kusano 7d535a
  /* register window class */
kusano 7d535a
  ZeroMemory(&wc, sizeof(WNDCLASS));
kusano 7d535a
  wc.hInstance = GetModuleHandle(NULL);
kusano 7d535a
  wc.lpfnWndProc = DefWindowProc;
kusano 7d535a
  wc.lpszClassName = "GLEW";
kusano 7d535a
  if (0 == RegisterClass(&wc)) return GL_TRUE;
kusano 7d535a
  /* create window */
kusano 7d535a
  ctx->wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, 
kusano 7d535a
                          CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, 
kusano 7d535a
                          GetModuleHandle(NULL), NULL);
kusano 7d535a
  if (NULL == ctx->wnd) return GL_TRUE;
kusano 7d535a
  /* get the device context */
kusano 7d535a
  ctx->dc = GetDC(ctx->wnd);
kusano 7d535a
  if (NULL == ctx->dc) return GL_TRUE;
kusano 7d535a
  /* find pixel format */
kusano 7d535a
  ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
kusano 7d535a
  if (visual == -1) /* find default */
kusano 7d535a
  {
kusano 7d535a
    pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
kusano 7d535a
    pfd.nVersion = 1;
kusano 7d535a
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
kusano 7d535a
    visual = ChoosePixelFormat(ctx->dc, &pfd);
kusano 7d535a
    if (0 == visual) return GL_TRUE;
kusano 7d535a
  }
kusano 7d535a
  /* set the pixel format for the dc */
kusano 7d535a
  if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;
kusano 7d535a
  /* create rendering context */
kusano 7d535a
  ctx->rc = wglCreateContext(ctx->dc);
kusano 7d535a
  if (NULL == ctx->rc) return GL_TRUE;
kusano 7d535a
  if (FALSE == wglMakeCurrent(ctx->dc, ctx->rc)) return GL_TRUE;
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void DestroyContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  if (NULL == ctx) return;
kusano 7d535a
  if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);
kusano 7d535a
  if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());
kusano 7d535a
  if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
kusano 7d535a
  if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);
kusano 7d535a
  UnregisterClass("GLEW", GetModuleHandle(NULL));
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
kusano 7d535a
void InitContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  ctx->ctx = NULL;
kusano 7d535a
  ctx->octx = NULL;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
GLboolean CreateContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  int attrib[] = { AGL_RGBA, AGL_NONE };
kusano 7d535a
  AGLPixelFormat pf;
kusano 7d535a
  /* check input */
kusano 7d535a
  if (NULL == ctx) return GL_TRUE;
kusano 7d535a
  /*int major, minor;
kusano 7d535a
  SetPortWindowPort(wnd);
kusano 7d535a
  aglGetVersion(&major, &minor);
kusano 7d535a
  fprintf(stderr, "GL %d.%d\n", major, minor);*/
kusano 7d535a
  pf = aglChoosePixelFormat(NULL, 0, attrib);
kusano 7d535a
  if (NULL == pf) return GL_TRUE;
kusano 7d535a
  ctx->ctx = aglCreateContext(pf, NULL);
kusano 7d535a
  if (NULL == ctx->ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
kusano 7d535a
  aglDestroyPixelFormat(pf);
kusano 7d535a
  /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
kusano 7d535a
  ctx->octx = aglGetCurrentContext();
kusano 7d535a
  if (GL_FALSE == aglSetCurrentContext(ctx->ctx)) return GL_TRUE;
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void DestroyContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  if (NULL == ctx) return;
kusano 7d535a
  aglSetCurrentContext(ctx->octx);
kusano 7d535a
  if (NULL != ctx->ctx) aglDestroyContext(ctx->ctx);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
kusano 7d535a
kusano 7d535a
void InitContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  ctx->dpy = NULL;
kusano 7d535a
  ctx->vi = NULL;
kusano 7d535a
  ctx->ctx = NULL;
kusano 7d535a
  ctx->wnd = 0;
kusano 7d535a
  ctx->cmap = 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
GLboolean CreateContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
kusano 7d535a
  int erb, evb;
kusano 7d535a
  XSetWindowAttributes swa;
kusano 7d535a
  /* check input */
kusano 7d535a
  if (NULL == ctx) return GL_TRUE;
kusano 7d535a
  /* open display */
kusano 7d535a
  ctx->dpy = XOpenDisplay(display);
kusano 7d535a
  if (NULL == ctx->dpy) return GL_TRUE;
kusano 7d535a
  /* query for glx */
kusano 7d535a
  if (!glXQueryExtension(ctx->dpy, &erb, &evb)) return GL_TRUE;
kusano 7d535a
  /* choose visual */
kusano 7d535a
  ctx->vi = glXChooseVisual(ctx->dpy, DefaultScreen(ctx->dpy), attrib);
kusano 7d535a
  if (NULL == ctx->vi) return GL_TRUE;
kusano 7d535a
  /* create context */
kusano 7d535a
  ctx->ctx = glXCreateContext(ctx->dpy, ctx->vi, None, True);
kusano 7d535a
  if (NULL == ctx->ctx) return GL_TRUE;
kusano 7d535a
  /* create window */
kusano 7d535a
  /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
kusano 7d535a
  ctx->cmap = XCreateColormap(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
kusano 7d535a
                              ctx->vi->visual, AllocNone);
kusano 7d535a
  swa.border_pixel = 0;
kusano 7d535a
  swa.colormap = ctx->cmap;
kusano 7d535a
  ctx->wnd = XCreateWindow(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen), 
kusano 7d535a
                           0, 0, 1, 1, 0, ctx->vi->depth, InputOutput, ctx->vi->visual, 
kusano 7d535a
                           CWBorderPixel | CWColormap, &swa);
kusano 7d535a
  /* make context current */
kusano 7d535a
  if (!glXMakeCurrent(ctx->dpy, ctx->wnd, ctx->ctx)) return GL_TRUE;
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void DestroyContext (GLContext* ctx)
kusano 7d535a
{
kusano 7d535a
  if (NULL != ctx->dpy && NULL != ctx->ctx) glXDestroyContext(ctx->dpy, ctx->ctx);
kusano 7d535a
  if (NULL != ctx->dpy && 0 != ctx->wnd) XDestroyWindow(ctx->dpy, ctx->wnd);
kusano 7d535a
  if (NULL != ctx->dpy && 0 != ctx->cmap) XFreeColormap(ctx->dpy, ctx->cmap);
kusano 7d535a
  if (NULL != ctx->vi) XFree(ctx->vi);
kusano 7d535a
  if (NULL != ctx->dpy) XCloseDisplay(ctx->dpy);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
kusano 7d535a
kusano 7d535a
GLboolean ParseArgs (int argc, char** argv)
kusano 7d535a
{
kusano 7d535a
  int p = 0;
kusano 7d535a
  while (p < argc)
kusano 7d535a
  {
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
    if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
kusano 7d535a
    {
kusano 7d535a
      if (++p >= argc) return GL_TRUE;
kusano 7d535a
      display = NULL;
kusano 7d535a
      visual = strtol(argv[p], NULL, 0);
kusano 7d535a
    }
kusano 7d535a
    else if (!strcmp(argv[p], "-a"))
kusano 7d535a
    {
kusano 7d535a
      showall = 1;
kusano 7d535a
    }
kusano 7d535a
    else if (!strcmp(argv[p], "-s"))
kusano 7d535a
    {
kusano 7d535a
      displaystdout = 1;
kusano 7d535a
    }
kusano 7d535a
    else if (!strcmp(argv[p], "-h"))
kusano 7d535a
    {
kusano 7d535a
      return GL_TRUE;
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
      return GL_TRUE;
kusano 7d535a
#else
kusano 7d535a
    if (!strcmp(argv[p], "-display"))
kusano 7d535a
    {
kusano 7d535a
      if (++p >= argc) return GL_TRUE;
kusano 7d535a
      display = argv[p];
kusano 7d535a
    }
kusano 7d535a
    else if (!strcmp(argv[p], "-visual"))
kusano 7d535a
    {
kusano 7d535a
      if (++p >= argc) return GL_TRUE;
kusano 7d535a
      visual = (int)strtol(argv[p], NULL, 0);
kusano 7d535a
    }
kusano 7d535a
    else if (!strcmp(argv[p], "-h"))
kusano 7d535a
    {
kusano 7d535a
      return GL_TRUE;
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
      return GL_TRUE;
kusano 7d535a
#endif
kusano 7d535a
    p++;
kusano 7d535a
  }
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}