diff options
Diffstat (limited to 'test_glXCreateWindow.c')
-rw-r--r-- | test_glXCreateWindow.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/test_glXCreateWindow.c b/test_glXCreateWindow.c new file mode 100644 index 0000000..8ee1898 --- /dev/null +++ b/test_glXCreateWindow.c @@ -0,0 +1,88 @@ +/* This case is to test the glXCreateWindow() support. + * compile: + * gcc -o test_glXCreateWindow test_glXCreateWindow.c -lGL + * run: + * LIBGL_ALWAYS_SOFTWARE=yes ./test_glXCreateWindow + * + * Result: + * The case should have no any output suppose the API works well. + * Right now the mesa will report: + * failed to create drawable + */ +#include<stdio.h> +#include<stdlib.h> +#include<X11/X.h> +#include<X11/Xlib.h> +#include<GL/gl.h> +#include<GL/glx.h> + +static const int attributes[] = { + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DOUBLEBUFFER, GL_TRUE, + None +}; + +int main(void) +{ + GLXFBConfig config = NULL; + GLXFBConfig *configs = NULL; + + Window dummy_xwin; + XVisualInfo *xvisinfo; + int major; + int minor; + int n_configs, i; + GLXDrawable dummy_drawable; + GLXWindow dummy_glxwin; + + Display *xdisplay = XOpenDisplay(NULL); + int xscreen_num = DefaultScreen (xdisplay); + Window root_xwin = DefaultRootWindow (xdisplay); + + configs = glXChooseFBConfig (xdisplay, + xscreen_num, + attributes, + &n_configs); + if (configs) + { + config = configs[0]; + XFree (configs); + } + else + { + fprintf (stderr, "Unable to find config!\n"); + return; + } + + xvisinfo = glXGetVisualFromFBConfig (xdisplay, config); + if (xvisinfo == None) + { + fprintf (stderr, "Unable to retrieve the X11 visual!\n"); + return; + } + + dummy_xwin = XCreateWindow (xdisplay, root_xwin, + 100, 100, 200, 200, + 0, + xvisinfo->depth, + CopyFromParent, + xvisinfo->visual, + None, + None); + + if (glXQueryVersion (xdisplay, &major, &minor) && + major == 1 && minor >= 3) + { + dummy_glxwin = glXCreateWindow (xdisplay, + config, + dummy_xwin, + NULL); + } + else + { + fprintf (stderr, "The test cannot be performed in current GLX version : %d.%d\n", major, minor); + } + + return; +} |