>>102026230
Here's my opengl main() for x11, enjoy.
int main() {
Display* display = XOpenDisplay(NULL);
int glxAttribs[] = {
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_ALPHA_SIZE, 8,
0
};
XVisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), glxAttribs);
Colormap colormap = XCreateColormap(display, RootWindow(display, visualInfo->screen), visualInfo->visual, AllocNone);
XSetWindowAttributes winAttribs;
winAttribs.colormap = colormap;
winAttribs.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask;
Window window = XCreateWindow(
display,
RootWindow(display, visualInfo->screen),
0, 0, FRAME_WIDTH, FRAME_HEIGHT,
0, // border
visualInfo->depth,
InputOutput,
visualInfo->visual,
CWColormap | CWEventMask,
&winAttribs
);
XMapWindow(display, window);
#if FULLSCREEN
Atom state = XInternAtom(display, "_NET_WM_STATE", true);
Atom fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", true);
XChangeProperty(display, window, state, XA_ATOM, 32, PropModeReplace, (unsigned char *)&fullscreen, 1);
#endif
XkbSetDetectableAutoRepeat(display, true, NULL);
XSync(display, false);
std::thread glThread = std::thread(runOpenGL, display, window, visualInfo);
XEvent event;
while (control.run) {
XNextEvent(display, &event);
switch (event.type) {
case Expose:
windowWidth = event.xexpose.width;
windowHeight = event.xexpose.height;
break;
case KeyPress:
control.keyDown(XLookupKeysym(&event.xkey, 0));
break;
case KeyRelease:
control.keyUp(XLookupKeysym(&event.xkey, 0));
break;
}
}
printf("SHUTTING DOWN...\n");
glThread.join();
XFree(visualInfo);
XDestroyWindow(display, window);
XFreeColormap(display, colormap);
XCloseDisplay(display);
return 0;
}