2003-07-06 15:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
int main (int argc, char** argv)
|
2003-07-06 15:01:13 +00:00
|
|
|
{
|
|
|
|
GLuint err;
|
2004-02-01 21:26:11 +00:00
|
|
|
char* display = NULL;
|
|
|
|
int visual = -1;
|
|
|
|
|
|
|
|
if (glewParseArgs(argc-1, argv+1, &display, &visual))
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
fprintf(stderr, "Usage: glewinfo [-pf <id>]\n");
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "Usage: glewinfo [-display <display>] [-visual <id>]\n");
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (GL_TRUE == glewCreateContext(display, &visual))
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: glewCreateContext failed\n");
|
|
|
|
glewDestroyContext();
|
|
|
|
return 1;
|
|
|
|
}
|
2003-07-06 15:01:13 +00:00
|
|
|
glewExperimental = GL_TRUE;
|
|
|
|
err = glewInit();
|
|
|
|
if (GLEW_OK != err)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
|
2003-09-26 13:49:28 +00:00
|
|
|
glewDestroyContext();
|
2003-07-06 15:01:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2003-07-06 20:03:33 +00:00
|
|
|
#ifdef _WIN32
|
2003-07-06 15:01:13 +00:00
|
|
|
f = fopen("glewinfo.txt", "w");
|
|
|
|
if (f == NULL) f = stdout;
|
2003-07-06 20:03:33 +00:00
|
|
|
#else
|
|
|
|
f = stdout;
|
|
|
|
#endif
|
2003-07-06 15:01:13 +00:00
|
|
|
fprintf(f, "---------------------------\n");
|
|
|
|
fprintf(f, " GLEW Extension Info\n");
|
|
|
|
fprintf(f, "---------------------------\n\n");
|
2004-02-01 21:26:11 +00:00
|
|
|
fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION));
|
2004-02-01 21:28:36 +00:00
|
|
|
#ifdef _WIN32
|
2004-02-01 22:27:31 +00:00
|
|
|
fprintf(f, "Reporting capabilities of pixelformat %d\n", visual);
|
2004-02-01 21:28:36 +00:00
|
|
|
#else
|
2004-02-01 22:27:31 +00:00
|
|
|
fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n",
|
2004-02-01 21:34:09 +00:00
|
|
|
display == NULL ? getenv("DISPLAY") : display, visual);
|
2004-02-01 21:28:36 +00:00
|
|
|
#endif
|
2003-07-06 15:01:13 +00:00
|
|
|
fprintf(f, "Running on a %s from %s\n",
|
|
|
|
glGetString(GL_RENDERER), glGetString(GL_VENDOR));
|
|
|
|
fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION));
|
|
|
|
glewInfo();
|
|
|
|
#ifdef _WIN32
|
|
|
|
wglewInfo();
|
|
|
|
#else
|
|
|
|
glxewInfo();
|
|
|
|
#endif
|
|
|
|
if (f != stdout) fclose(f);
|
2003-09-26 13:49:28 +00:00
|
|
|
glewDestroyContext();
|
2003-07-06 15:01:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-09-26 13:49:28 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual)
|
|
|
|
{
|
|
|
|
int p = 0;
|
|
|
|
while (p < argc)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (!strcmp(argv[p], "-pf"))
|
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
|
|
|
*visual = atoi(argv[p++]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return GL_TRUE;
|
|
|
|
#else
|
|
|
|
if (!strcmp(argv[p], "-display"))
|
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
|
|
|
*display = argv[p++];
|
|
|
|
}
|
|
|
|
else if (!strcmp(argv[p], "-visual") || !strcmp(argv[p], "-pf"))
|
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
|
|
|
*visual = atoi(argv[p++]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return GL_TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2003-09-26 13:49:28 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
2003-09-26 14:45:00 +00:00
|
|
|
HWND wnd = NULL;
|
|
|
|
HDC dc = NULL;
|
|
|
|
HGLRC rc = NULL;
|
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
GLboolean glewCreateContext (const char* display, int* visual)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* register window class */
|
2003-09-26 13:49:28 +00:00
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASS));
|
|
|
|
wc.hInstance = GetModuleHandle(NULL);
|
|
|
|
wc.lpfnWndProc = DefWindowProc;
|
|
|
|
wc.lpszClassName = "GLEW";
|
|
|
|
if (0 == RegisterClass(&wc)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create window */
|
2003-09-26 13:49:28 +00:00
|
|
|
wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
|
|
|
|
if (NULL == wnd) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* get the device context */
|
2003-09-26 13:49:28 +00:00
|
|
|
dc = GetDC(wnd);
|
|
|
|
if (NULL == dc) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* find pixel format */
|
2003-09-26 13:49:28 +00:00
|
|
|
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
2004-02-01 21:26:11 +00:00
|
|
|
if (*visual == -1) /* find default */
|
|
|
|
{
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
|
|
|
|
*visual = ChoosePixelFormat(dc, &pfd);
|
|
|
|
if (*visual == 0) return GL_TRUE;
|
|
|
|
}
|
2003-09-26 14:17:28 +00:00
|
|
|
/* set the pixel format for the dc */
|
2004-02-01 21:26:11 +00:00
|
|
|
if (FALSE == SetPixelFormat(dc, *visual, &pfd)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create rendering context */
|
2003-09-26 13:49:28 +00:00
|
|
|
rc = wglCreateContext(dc);
|
|
|
|
if (NULL == rc) return GL_TRUE;
|
|
|
|
if (FALSE == wglMakeCurrent(dc, rc)) return GL_TRUE;
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
|
|
|
if (NULL != rc) wglMakeCurrent(NULL, NULL);
|
|
|
|
if (NULL != rc) wglDeleteContext(wglGetCurrentContext());
|
|
|
|
if (NULL != wnd && NULL != dc) ReleaseDC(wnd, dc);
|
|
|
|
if (NULL != wnd) DestroyWindow(wnd);
|
|
|
|
UnregisterClass("GLEW", GetModuleHandle(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2003-10-27 01:06:34 +00:00
|
|
|
# if defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
|
2003-09-26 13:49:28 +00:00
|
|
|
|
2003-10-27 01:06:34 +00:00
|
|
|
#include <AGL/agl.h>
|
|
|
|
|
|
|
|
AGLContext ctx, octx;
|
2003-09-27 06:56:18 +00:00
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
GLboolean glewCreateContext (const char* display, int* visual)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
2003-10-27 01:06:34 +00:00
|
|
|
int attrib[] = { AGL_RGBA, AGL_NONE };
|
|
|
|
AGLPixelFormat pf;
|
|
|
|
//int major, minor;
|
|
|
|
//SetPortWindowPort(wnd);
|
|
|
|
//aglGetVersion(&major, &minor);
|
|
|
|
//fprintf(stderr, "GL %d.%d\n", major, minor);
|
|
|
|
pf = aglChoosePixelFormat(NULL, 0, attrib);
|
|
|
|
if (NULL == pf) return GL_TRUE;
|
|
|
|
ctx = aglCreateContext(pf, NULL);
|
|
|
|
if (NULL == ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
|
|
|
|
aglDestroyPixelFormat(pf);
|
|
|
|
//aglSetDrawable(ctx, GetWindowPort(wnd));
|
|
|
|
octx = aglGetCurrentContext();
|
|
|
|
if (NULL == aglSetCurrentContext(ctx)) return GL_TRUE;
|
2003-09-27 06:56:18 +00:00
|
|
|
return GL_FALSE;
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
2003-10-27 01:06:34 +00:00
|
|
|
aglSetCurrentContext(octx);
|
|
|
|
if (NULL != ctx) aglDestroyContext(ctx);
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
2003-10-27 01:06:34 +00:00
|
|
|
# else /* __linux || __sgi || (__APPLE__ && GLEW_APPLE_GLX) */
|
2003-09-26 13:49:28 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2003-09-26 14:45:00 +00:00
|
|
|
Display* dpy = NULL;
|
|
|
|
XVisualInfo* vi = NULL;
|
|
|
|
GLXContext ctx = NULL;
|
|
|
|
Window wnd;
|
2003-09-26 16:07:24 +00:00
|
|
|
Colormap cmap;
|
2003-09-26 14:17:28 +00:00
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
GLboolean glewCreateContext (const char* display, int* visual)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
2003-10-27 08:57:44 +00:00
|
|
|
int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
|
2003-09-26 14:17:28 +00:00
|
|
|
int erb, evb;
|
2003-09-26 16:07:24 +00:00
|
|
|
XSetWindowAttributes swa;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* open display */
|
2004-02-01 21:26:11 +00:00
|
|
|
dpy = XOpenDisplay(display);
|
2003-09-26 14:17:28 +00:00
|
|
|
if (NULL == dpy) return GL_TRUE;
|
|
|
|
/* query for glx */
|
2003-09-26 14:45:00 +00:00
|
|
|
if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* choose visual */
|
|
|
|
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
|
|
|
|
if (NULL == vi) return GL_TRUE;
|
2004-02-01 21:34:09 +00:00
|
|
|
*visual = vi->visualid;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create context */
|
|
|
|
ctx = glXCreateContext(dpy, vi, None, True);
|
|
|
|
if (NULL == ctx) return GL_TRUE;
|
|
|
|
/* create window */
|
2003-09-26 16:33:19 +00:00
|
|
|
/*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
|
2003-09-26 16:07:24 +00:00
|
|
|
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
|
|
|
|
swa.border_pixel = 0;
|
|
|
|
swa.colormap = cmap;
|
2003-09-26 16:34:47 +00:00
|
|
|
wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 256, 256, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap, &swa);
|
2003-09-26 16:33:19 +00:00
|
|
|
/* make context current */
|
2003-09-26 14:17:28 +00:00
|
|
|
if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
|
|
|
|
return GL_FALSE;
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
2003-09-26 14:45:00 +00:00
|
|
|
if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx);
|
|
|
|
if (NULL != dpy) XDestroyWindow(dpy, wnd);
|
2003-09-26 16:12:10 +00:00
|
|
|
if (NULL != dpy) XFreeColormap(dpy, cmap);
|
2003-09-26 14:45:00 +00:00
|
|
|
if (NULL != vi) XFree(vi);
|
|
|
|
if (NULL != dpy) XCloseDisplay(dpy);
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
2003-09-26 14:17:28 +00:00
|
|
|
# endif /* __linux || __sgi */
|
2003-09-26 13:49:28 +00:00
|
|
|
|
|
|
|
#endif
|