summaryrefslogtreecommitdiff
path: root/makecurrenttest2.c
blob: f40f89f98ce3e3c7d950a995ff4f087a51c50951 (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

#include <X11/X.h>
#include <X11/Xlib.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>

//
// gcc -g -Wall -o makecurrenttest makecurrenttest.c -lX11 -lGL
//

static Window make_rgb_db_window( Display *dpy, XVisualInfo *visinfo,
                                  unsigned int width, unsigned int height )
{
   int scrnum;
   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   Window win;

   scrnum = DefaultScreen( dpy );
   root = RootWindow( dpy, scrnum );

   /* window attributes */
   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;

   win = XCreateWindow( dpy, root, 0, 0, width, height,
                        0, visinfo->depth, InputOutput,
                        visinfo->visual, mask, &attr );

   return win;
}


int main()
{
  int i;

  // Open the display
  Display *dpy = XOpenDisplay(NULL);
  assert(dpy);

  int attrib[] = { GLX_RGBA,
                   GLX_RED_SIZE, 1,
                   GLX_GREEN_SIZE, 1,
                   GLX_BLUE_SIZE, 1,
                   GLX_DOUBLEBUFFER,
                   None };

  XVisualInfo *visinfo;
  visinfo = glXChooseVisual( dpy, DefaultScreen(dpy), attrib );
  if (!visinfo) {
    printf("Error: couldn't get an RGB, Double-buffered visual\n");
    assert(0);
  }

  for (i=0; i < 2; i++)
    {
      // Create the window
      Window w = make_rgb_db_window(dpy,visinfo,200,100);

      // Map the window
      XMapWindow(dpy, w);

      // Create context
      GLXContext ctx = glXCreateContext(dpy, visinfo, NULL, True );
      if (!ctx) {
        printf("Error: glXCreateContext failed\n");
        assert(0);
      }

      // Make current
      glXMakeCurrent(dpy, w, ctx);

      // Destroy window
      XDestroyWindow(dpy, w);
    }

  return 0;
}