added visual selection to glewinfo

git-svn-id: https://glew.svn.sourceforge.net/svnroot/glew/trunk/glew@214 783a27ee-832a-0410-bc00-9f386506c6dd
This commit is contained in:
ikits 2004-02-01 22:59:49 +00:00
parent 3a0f14c839
commit 1887f4a67c
1 changed files with 26 additions and 8 deletions

View File

@ -189,9 +189,10 @@ void glewDestroyContext ()
Display* dpy = NULL; Display* dpy = NULL;
XVisualInfo* vi = NULL; XVisualInfo* vi = NULL;
XVisualInfo* vis = NULL;
GLXContext ctx = NULL; GLXContext ctx = NULL;
Window wnd; Window wnd = 0;
Colormap cmap; Colormap cmap = 0;
GLboolean glewCreateContext (const char* display, int* visual) GLboolean glewCreateContext (const char* display, int* visual)
{ {
@ -204,9 +205,23 @@ GLboolean glewCreateContext (const char* display, int* visual)
/* query for glx */ /* query for glx */
if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE; if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
/* choose visual */ /* choose visual */
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib); if (*visual == -1)
if (NULL == vi) return GL_TRUE; {
*visual = vi->visualid; vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
if (NULL == vi) return GL_TRUE;
*visual = (int)XVisualIDFromVisual(vi->visual);
}
else
{
int n_vis, i;
vis = XGetVisualInfo(dpy, 0, NULL, &n_vis);
for (i=0; i<n_vis; i++)
{
if ((int)XVisualIDFromVisual(vis[i].visual) == *visual)
vi = &vis[i];
}
if (vi == NULL) return GL_TRUE;
}
/* create context */ /* create context */
ctx = glXCreateContext(dpy, vi, None, True); ctx = glXCreateContext(dpy, vi, None, True);
if (NULL == ctx) return GL_TRUE; if (NULL == ctx) return GL_TRUE;
@ -224,9 +239,12 @@ GLboolean glewCreateContext (const char* display, int* visual)
void glewDestroyContext () void glewDestroyContext ()
{ {
if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx); if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx);
if (NULL != dpy) XDestroyWindow(dpy, wnd); if (NULL != dpy && 0 != wnd) XDestroyWindow(dpy, wnd);
if (NULL != dpy) XFreeColormap(dpy, cmap); if (NULL != dpy && cmap != 0) XFreeColormap(dpy, cmap);
if (NULL != vi) XFree(vi); if (NULL != vis)
XFree(vis);
else if (NULL != vi)
XFree(vi);
if (NULL != dpy) XCloseDisplay(dpy); if (NULL != dpy) XCloseDisplay(dpy);
} }