From d092e87d8ebdc4760fe9611f3d9eb9ff0a0653f4 Mon Sep 17 00:00:00 2001 From: ikits Date: Sun, 1 Feb 2004 21:26:11 +0000 Subject: [PATCH] added command line flags to glewinfo git-svn-id: https://glew.svn.sourceforge.net/svnroot/glew/trunk/glew@208 783a27ee-832a-0410-bc00-9f386506c6dd --- auto/src/glewinfo_post.c | 81 +++++++++++++++++++++++++++++++++------- auto/src/glewinfo_pre.c | 4 +- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/auto/src/glewinfo_post.c b/auto/src/glewinfo_post.c index b5f0f17..1a00a0e 100644 --- a/auto/src/glewinfo_post.c +++ b/auto/src/glewinfo_post.c @@ -4,10 +4,27 @@ /* ------------------------------------------------------------------------ */ -int main () +int main (int argc, char** argv) { GLuint err; - if (GL_TRUE == glewCreateContext()) + char* display = NULL; + int visual = -1; +#ifdef _WIN32 + const char* visual_str = "PixelFormat"; +#else + const char* visual_str = "Visual"; +#endif + + if (glewParseArgs(argc-1, argv+1, &display, &visual)) + { +#ifdef _WIN32 + fprintf(stderr, "Usage: glewinfo [-pf ]\n"); +#else + fprintf(stderr, "Usage: glewinfo [-display ] [-visual ]\n"); +#endif + return 1; + } + if (GL_TRUE == glewCreateContext(display, &visual)) { fprintf(stderr, "Error: glewCreateContext failed\n"); glewDestroyContext(); @@ -30,10 +47,11 @@ int main () fprintf(f, "---------------------------\n"); fprintf(f, " GLEW Extension Info\n"); fprintf(f, "---------------------------\n\n"); + fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION)); + fprintf(f, "Reporting capabilities of %s %d\n", visual_str, visual); 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)); - fprintf(f, "GLEW version %s is supported\n", glewGetString(GLEW_VERSION)); glewInfo(); #ifdef _WIN32 wglewInfo(); @@ -47,17 +65,49 @@ int main () /* ------------------------------------------------------------------------ */ +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; +} + +/* ------------------------------------------------------------------------ */ + #ifdef _WIN32 HWND wnd = NULL; HDC dc = NULL; HGLRC rc = NULL; -GLboolean glewCreateContext () +GLboolean glewCreateContext (const char* display, int* visual) { WNDCLASS wc; PIXELFORMATDESCRIPTOR pfd; - int pf; /* register window class */ ZeroMemory(&wc, sizeof(WNDCLASS)); wc.hInstance = GetModuleHandle(NULL); @@ -72,13 +122,16 @@ GLboolean glewCreateContext () if (NULL == dc) return GL_TRUE; /* find pixel format */ ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR)); - pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - pf = ChoosePixelFormat(dc, &pfd); - if (pf == 0) return GL_TRUE; + 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; + } /* set the pixel format for the dc */ - if (FALSE == SetPixelFormat(dc, pf, &pfd)) return GL_TRUE; + if (FALSE == SetPixelFormat(dc, *visual, &pfd)) return GL_TRUE; /* create rendering context */ rc = wglCreateContext(dc); if (NULL == rc) return GL_TRUE; @@ -105,7 +158,7 @@ void glewDestroyContext () AGLContext ctx, octx; -GLboolean glewCreateContext () +GLboolean glewCreateContext (const char* display, int* visual) { int attrib[] = { AGL_RGBA, AGL_NONE }; AGLPixelFormat pf; @@ -140,13 +193,13 @@ GLXContext ctx = NULL; Window wnd; Colormap cmap; -GLboolean glewCreateContext () +GLboolean glewCreateContext (const char* display, int* visual) { int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; int erb, evb; XSetWindowAttributes swa; /* open display */ - dpy = XOpenDisplay(NULL); + dpy = XOpenDisplay(display); if (NULL == dpy) return GL_TRUE; /* query for glx */ if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE; diff --git a/auto/src/glewinfo_pre.c b/auto/src/glewinfo_pre.c index 9db0cc4..97ac4b3 100644 --- a/auto/src/glewinfo_pre.c +++ b/auto/src/glewinfo_pre.c @@ -30,6 +30,7 @@ */ #include +#include #include #include #if defined(_WIN32) @@ -40,7 +41,8 @@ static FILE* f; -GLboolean glewCreateContext (); +GLboolean glewCreateContext (const char* display, int* visual); +GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual); void glewDestroyContext (); /* ------------------------------------------------------------------------- */