-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.cpp
89 lines (69 loc) · 1.65 KB
/
host.cpp
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
89
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <GL/gl.h>
#include <GL/glx.h>
// Initialization
static Window create_window(Display *display, unsigned int width, unsigned int height)
{
int attrib[] = { GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None
};
int screen = DefaultScreen(display);
Window root = RootWindow(display, screen);
XVisualInfo *visualinfo = glXChooseVisual(display, screen, attrib);
if (!visualinfo)
{
printf("error, couldn't get the correct buffer.\n");
exit(1);
}
XSetWindowAttributes attr = {0};
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(display, root, visualinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Window window = XCreateWindow(
display,
root,
0,
0,
width,
height,
0,
visualinfo->depth,
InputOutput,
visualinfo->visual,
mask,
&attr);
XMapWindow(display, window);
return window;
}
// Event Loop
static void event_loop(Display *display, Window window)
{
XEvent event;
while (1)
{
XNextEvent(display, &event);
printf("event: %d\n", event.type);
}
}
// Main
int main(int argc, char* argv[])
{
Display *display = XOpenDisplay(NULL);
Window window = create_window(display, 400, 400);
printf("window = %u\n", window);
event_loop(display, window);
return 0;
}