]> icculus.org git repositories - dana/openbox.git/blob - render2/test.c
the kernel is using th gl shit to render itself, but with the old style frame shit...
[dana/openbox.git] / render2 / test.c
1 #include <stdio.h>
2 #include <X11/Xlib.h>
3 #include <X11/Xatom.h>
4 #include <X11/extensions/shape.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include "render.h"
8 #include <glib.h>
9
10 static int x_error_handler(Display * disp, XErrorEvent * error)
11 {
12     char buf[1024];
13     XGetErrorText(disp, error->error_code, buf, 1024);
14     printf("%s\n", buf);
15     return 0;
16 }
17
18 #define X 10
19 #define Y 10
20 #define W 100
21 #define H 100
22
23 int main()
24 {
25     Display *display;
26     Window win;
27     XEvent report, report2;
28     XClassHint chint;
29     Atom delete_win, protocols;
30     int quit;
31
32     struct RrInstance *inst;
33     struct RrSurface *sur;
34     struct RrColor pri, sec;
35
36     if (!(display = XOpenDisplay(NULL))) {
37         fprintf(stderr, "couldn't connect to X server in DISPLAY\n");
38         return EXIT_FAILURE;
39     }
40     XSetErrorHandler(x_error_handler);
41     win = XCreateWindow(display, RootWindow(display, DefaultScreen(display)),
42                         X, Y, W, H, 0, 
43                         CopyFromParent,   /* depth */
44                         CopyFromParent,   /* class */
45                         CopyFromParent,   /* visual */
46                         0,                /* valuemask */
47                         0);               /* attributes */
48     XMapWindow(display, win);
49     XSelectInput(display, win, ExposureMask | StructureNotifyMask);
50
51     chint.res_name = "rendertest";
52     chint.res_class = "Rendertest";
53     XSetClassHint(display, win, &chint);
54
55     delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
56     protocols = XInternAtom(display, "WM_PROTOCOLS", False);
57     XSetWMProtocols(display, win, &delete_win, 1);
58
59     /* init Render */
60     if (!(inst = RrInstanceNew(display, DefaultScreen(display)))) {
61         fprintf(stderr, "couldn't initialize the Render library "
62                 "(no suitable GL support found)\n");
63         return EXIT_FAILURE;
64     }
65
66     sur = RrSurfaceNew(inst, RR_SURFACE_PLANAR, win, 0);
67     RrSurfaceSetArea(sur, X, Y, W, H);
68     RrColorSet(&pri, 0, 0, 0, 0);
69     RrColorSet(&sec, 1, 1, 1, 0);
70     RrPlanarSet(sur, RR_PLANAR_PIPECROSS, RR_RAISED_INNER, &pri, &sec,
71                 0, NULL);
72
73     quit = 0;
74     while (!quit) {
75         XNextEvent(display, &report);
76         switch (report.type) {
77         case ClientMessage:
78             if ((Atom)report.xclient.message_type == protocols)
79                 if ((Atom)report.xclient.data.l[0] == delete_win)
80                     quit = 1;
81         case Expose:
82             if (XCheckTypedWindowEvent(display, win, ConfigureNotify,
83                                        &report2)) {
84                 XPutBackEvent(display, &report);
85                 XPutBackEvent(display, &report2);
86                 /* fall through ... */
87             } else {
88                 while (XCheckTypedWindowEvent(display, win, Expose, &report));
89                 RrPaint(sur);
90                 break;
91             }
92         case ConfigureNotify:
93             while (XCheckTypedWindowEvent(display, win, ConfigureNotify,
94                                           &report));
95             RrSurfaceSetSize(sur,
96                              report.xconfigure.width,
97                              report.xconfigure.height);
98             break;
99         }
100
101     }
102
103     RrInstanceFree(inst);
104
105     return 1;
106 }