summaryrefslogtreecommitdiff
path: root/test_glXCreateWindow.c
blob: 8ee1898c881b9c7905e4ae50b459924cfc580903 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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;
}