]> icculus.org git repositories - dana/openbox.git/blob - render2/test.c
can render.. only it doesnt work yet
[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 int main()
19 {
20     Display *display;
21     Window win;
22     XEvent report;
23     XClassHint chint;
24     Atom delete_win, protocols;
25     int quit;
26
27     struct RrInstance *inst;
28     struct RrSurface *sur;
29     struct RrColor pri, sec;
30
31     if (!(display = XOpenDisplay(NULL))) {
32         fprintf(stderr, "couldn't connect to X server in DISPLAY\n");
33         return EXIT_FAILURE;
34     }
35     XSetErrorHandler(x_error_handler);
36     win = XCreateWindow(display, RootWindow(display, DefaultScreen(display)),
37                         10, 10, 100, 100, 0, 
38                         CopyFromParent,   /* depth */
39                         CopyFromParent,   /* class */
40                         CopyFromParent,   /* visual */
41                         0,                /* valuemask */
42                         0);               /* attributes */
43     XMapWindow(display, win);
44     XSelectInput(display, win, ExposureMask | StructureNotifyMask);
45
46     chint.res_name = "rendertest";
47     chint.res_class = "Rendertest";
48     XSetClassHint(display, win, &chint);
49
50     delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
51     protocols = XInternAtom(display, "WM_PROTOCOLS", False);
52     XSetWMProtocols(display, win, &delete_win, 1);
53
54     /* init Render */
55     if (!(inst = RrInit(display, DefaultScreen(display)))) {
56         fprintf(stderr, "couldn't initialize the Render library "
57                 "(no suitable GL support found)\n");
58         return EXIT_FAILURE;
59     }
60
61     sur = RrSurfaceNew(inst, RR_SURFACE_PLANAR, win, 0);
62     RrSurfaceSetArea(sur, 10, 10, 100, 100);
63     RrColorSet(&pri, 0, 0, 0, 0);
64     RrColorSet(&pri, 1, 1, 1, 0);
65     RrPlanarSet(sur, RR_PLANAR_VERTICAL, &pri, &sec);
66
67     quit = 0;
68     while (!quit) {
69         XNextEvent(display, &report);
70         switch (report.type) {
71         case ClientMessage:
72             if ((Atom)report.xclient.message_type == protocols)
73                 if ((Atom)report.xclient.data.l[0] == delete_win)
74                     quit = 1;
75         case Expose:
76             RrPaint(sur);
77             break;
78         case ConfigureNotify:
79             RrSurfaceSetArea(sur,
80                              report.xconfigure.x,
81                              report.xconfigure.y,
82                              report.xconfigure.width,
83                              report.xconfigure.height);
84             break;
85         }
86
87     }
88
89     RrDestroy(inst);
90
91     return 1;
92 }