kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif /* _WIN32 */
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
int main (int argc, char** argv)
kusano 7d535a
#else
kusano 7d535a
int main (void)
kusano 7d535a
#endif
kusano 7d535a
{
kusano 7d535a
  GLuint err;
kusano 7d535a
kusano 7d535a
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
  char* display = NULL;
kusano 7d535a
  int visual = -1;
kusano 7d535a
kusano 7d535a
  if (glewParseArgs(argc-1, argv+1, &display, &visual))
kusano 7d535a
  {
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
    fprintf(stderr, "Usage: glewinfo [-pf <id>]\n");</id>
kusano 7d535a
#else
kusano 7d535a
    fprintf(stderr, "Usage: glewinfo [-display <display>] [-visual <id>]\n");</id></display>
kusano 7d535a
#endif
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  if (GL_TRUE == glewCreateContext(&visual))
kusano 7d535a
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
kusano 7d535a
  if (GL_TRUE == glewCreateContext())
kusano 7d535a
#else
kusano 7d535a
  if (GL_TRUE == glewCreateContext(display, &visual))
kusano 7d535a
#endif
kusano 7d535a
  {
kusano 7d535a
    fprintf(stderr, "Error: glewCreateContext failed\n");
kusano 7d535a
    glewDestroyContext();
kusano 7d535a
    return 1;
kusano 7d535a
  }
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
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
    glewDestroyContext();
kusano 7d535a
    return 1;
kusano 7d535a
  }
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  f = fopen("glewinfo.txt", "w");
kusano 7d535a
  if (f == NULL) f = stdout;
kusano 7d535a
#else
kusano 7d535a
  f = stdout;
kusano 7d535a
#endif
kusano 7d535a
  fprintf(f, "---------------------------\n");
kusano 7d535a
  fprintf(f, "    GLEW Extension Info\n");
kusano 7d535a
  fprintf(f, "---------------------------\n\n");
kusano 7d535a
  fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION));
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  fprintf(f, "Reporting capabilities of pixelformat %d\n", visual);
kusano 7d535a
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
  fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n", 
kusano 7d535a
    display == NULL ? getenv("DISPLAY") : display, visual);
kusano 7d535a
#endif
kusano 7d535a
  fprintf(f, "Running on a %s from %s\n", 
kusano 7d535a
	  glGetString(GL_RENDERER), glGetString(GL_VENDOR));
kusano 7d535a
  fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION));
kusano 7d535a
  glewInfo();
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
  wglewInfo();
kusano 7d535a
#else
kusano 7d535a
  glxewInfo();
kusano 7d535a
#endif
kusano 7d535a
  if (f != stdout) fclose(f);
kusano 7d535a
  glewDestroyContext();
kusano 7d535a
  return 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
kusano 7d535a
GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual)
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 = 0;
kusano 7d535a
      *visual = strtol(argv[p++], NULL, 0);
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
kusano 7d535a
      return GL_TRUE;
kusano 7d535a
#endif
kusano 7d535a
  }
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#if defined(_WIN32)
kusano 7d535a
kusano 7d535a
HWND wnd = NULL;
kusano 7d535a
HDC dc = NULL;
kusano 7d535a
HGLRC rc = NULL;
kusano 7d535a
kusano 7d535a
GLboolean glewCreateContext (int* pixelformat)
kusano 7d535a
{
kusano 7d535a
  WNDCLASS wc;
kusano 7d535a
  PIXELFORMATDESCRIPTOR pfd;
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
  wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
kusano 7d535a
                     CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
kusano 7d535a
  if (NULL == wnd) return GL_TRUE;
kusano 7d535a
  /* get the device context */
kusano 7d535a
  dc = GetDC(wnd);
kusano 7d535a
  if (NULL == dc) return GL_TRUE;
kusano 7d535a
  /* find pixel format */
kusano 7d535a
  ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
kusano 7d535a
  if (*pixelformat == -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
    *pixelformat = ChoosePixelFormat(dc, &pfd);
kusano 7d535a
    if (*pixelformat == 0) return GL_TRUE;
kusano 7d535a
  }
kusano 7d535a
  /* set the pixel format for the dc */
kusano 7d535a
  if (FALSE == SetPixelFormat(dc, *pixelformat, &pfd)) return GL_TRUE;
kusano 7d535a
  /* create rendering context */
kusano 7d535a
  rc = wglCreateContext(dc);
kusano 7d535a
  if (NULL == rc) return GL_TRUE;
kusano 7d535a
  if (FALSE == wglMakeCurrent(dc, rc)) return GL_TRUE;
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void glewDestroyContext ()
kusano 7d535a
{
kusano 7d535a
  if (NULL != rc) wglMakeCurrent(NULL, NULL);
kusano 7d535a
  if (NULL != rc) wglDeleteContext(rc);
kusano 7d535a
  if (NULL != wnd && NULL != dc) ReleaseDC(wnd, dc);
kusano 7d535a
  if (NULL != wnd) DestroyWindow(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
#include <agl agl.h=""></agl>
kusano 7d535a
kusano 7d535a
AGLContext ctx, octx;
kusano 7d535a
kusano 7d535a
GLboolean glewCreateContext ()
kusano 7d535a
{
kusano 7d535a
  int attrib[] = { AGL_RGBA, AGL_NONE };
kusano 7d535a
  AGLPixelFormat pf;
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 = aglCreateContext(pf, NULL);
kusano 7d535a
  if (NULL == ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
kusano 7d535a
  aglDestroyPixelFormat(pf);
kusano 7d535a
  /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
kusano 7d535a
  octx = aglGetCurrentContext();
kusano 7d535a
  if (GL_FALSE == aglSetCurrentContext(ctx)) return GL_TRUE;
kusano 7d535a
  /* Needed for Regal on the Mac */
kusano 7d535a
  #if defined(GLEW_REGAL) && defined(__APPLE__)
kusano 7d535a
  RegalMakeCurrent(octx);
kusano 7d535a
  #endif
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void glewDestroyContext ()
kusano 7d535a
{
kusano 7d535a
  aglSetCurrentContext(octx);
kusano 7d535a
  if (NULL != ctx) aglDestroyContext(ctx);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/* ------------------------------------------------------------------------ */
kusano 7d535a
kusano 7d535a
#else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
kusano 7d535a
kusano 7d535a
Display* dpy = NULL;
kusano 7d535a
XVisualInfo* vi = NULL;
kusano 7d535a
XVisualInfo* vis = NULL;
kusano 7d535a
GLXContext ctx = NULL;
kusano 7d535a
Window wnd = 0;
kusano 7d535a
Colormap cmap = 0;
kusano 7d535a
kusano 7d535a
GLboolean glewCreateContext (const char* display, int* visual)
kusano 7d535a
{
kusano 7d535a
  int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
kusano 7d535a
  int erb, evb;
kusano 7d535a
  XSetWindowAttributes swa;
kusano 7d535a
  /* open display */
kusano 7d535a
  dpy = XOpenDisplay(display);
kusano 7d535a
  if (NULL == dpy) return GL_TRUE;
kusano 7d535a
  /* query for glx */
kusano 7d535a
  if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
kusano 7d535a
  /* choose visual */
kusano 7d535a
  if (*visual == -1)
kusano 7d535a
  {
kusano 7d535a
    vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
kusano 7d535a
    if (NULL == vi) return GL_TRUE;
kusano 7d535a
    *visual = (int)XVisualIDFromVisual(vi->visual);
kusano 7d535a
  }
kusano 7d535a
  else
kusano 7d535a
  {
kusano 7d535a
    int n_vis, i;
kusano 7d535a
    vis = XGetVisualInfo(dpy, 0, NULL, &n_vis);
kusano 7d535a
    for (i=0; i
kusano 7d535a
    {
kusano 7d535a
      if ((int)XVisualIDFromVisual(vis[i].visual) == *visual)
kusano 7d535a
        vi = &vis[i];
kusano 7d535a
    }
kusano 7d535a
    if (vi == NULL) return GL_TRUE;
kusano 7d535a
  }
kusano 7d535a
  /* create context */
kusano 7d535a
  ctx = glXCreateContext(dpy, vi, None, True);
kusano 7d535a
  if (NULL == 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
  cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
kusano 7d535a
  swa.border_pixel = 0;
kusano 7d535a
  swa.colormap = cmap;
kusano 7d535a
  wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 
kusano 7d535a
                      0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual, 
kusano 7d535a
                      CWBorderPixel | CWColormap, &swa);
kusano 7d535a
  /* make context current */
kusano 7d535a
  if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
kusano 7d535a
  return GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
void glewDestroyContext ()
kusano 7d535a
{
kusano 7d535a
  if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx);
kusano 7d535a
  if (NULL != dpy && 0 != wnd) XDestroyWindow(dpy, wnd);
kusano 7d535a
  if (NULL != dpy && 0 != cmap) XFreeColormap(dpy, cmap);
kusano 7d535a
  if (NULL != vis)
kusano 7d535a
    XFree(vis);
kusano 7d535a
  else if (NULL != vi)
kusano 7d535a
    XFree(vi);
kusano 7d535a
  if (NULL != dpy) XCloseDisplay(dpy);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */