2 #include <X11/Xlib-xcb.h>
4 #include "cube.h"
5 #include "cube-egl.h"
6 #include "cube-gles2.h"
8 #include "test.h"
10 using namespace std;
12 void main_x11()
13 {
14 Display* display = XOpenDisplay(NULL);
16 xcb_connection_t *c = XGetXCBConnection(display);
18 /* Get the first screen */
19 const xcb_setup_t *setup = xcb_get_setup (c);
20 xcb_screen_t *screen = xcb_setup_roots_iterator (setup).data;
22 /* Create the window */
24 uint32_t width;
25 uint32_t height;
27 if (s_fullscreen) {
28 width = screen->width_in_pixels;
29 height = screen->height_in_pixels;
30 } else {
31 width = 600;
32 height = 600;
33 }
35 const uint32_t xcb_window_attrib_mask = XCB_CW_EVENT_MASK;
36 const uint32_t xcb_window_attrib_list[] = {
37 XCB_EVENT_MASK_EXPOSURE,
38 };
40 xcb_window_t window = xcb_generate_id (c);
41 xcb_create_window (c, /* Connection */
42 XCB_COPY_FROM_PARENT, /* depth (same as root)*/
43 window, /* window Id */
44 screen->root, /* parent window */
45 0, 0, /* x, y */
46 width, height, /* width, height */
47 0, /* border_width */
48 XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
49 screen->root_visual, /* visual */
50 xcb_window_attrib_mask,
51 xcb_window_attrib_list);
54 #if 0 // Doesn't work
55 if (s_fullscreen) {
57 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, 0, 12, "_NET_WM_STATE");
58 xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(c, cookie, 0);
60 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, 24, "_NET_WM_STATE_FULLSCREEN");
61 xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
63 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, reply->atom, XCB_ATOM_ATOM , 32, 1, (void*)&reply2->atom);
64 }
65 #endif
67 xcb_map_window (c, window);
68 xcb_flush (c);
70 EglState egl(display);
71 EglSurface surface(egl, (void*)(uintptr_t)window);
72 GlScene scene;
74 scene.set_viewport(width, height);
76 int framenum = 0;
78 surface.make_current();
79 surface.swap_buffers();
81 xcb_generic_event_t *event;
82 while ( (event = xcb_poll_for_event (c)) ) {
84 surface.make_current();
85 scene.draw(framenum++);
86 surface.swap_buffers();
87 }
89 xcb_disconnect (c);
90 }