Skip to content

Instantly share code, notes, and snippets.

@haasn
Last active June 7, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haasn/7f2134a3e34378cff6782e5f63f8ea8d to your computer and use it in GitHub Desktop.
Save haasn/7f2134a3e34378cff6782e5f63f8ea8d to your computer and use it in GitHub Desktop.
Work-around for Kerbal Space Program under 10-bit displays (or any Unity game, really)
// Compile as kspfix.so and load with LD_PRELOAD
#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <GL/glx.h>
GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen, const int *attrib_list, int *nelements)
{
for (int *attr = (int *)attrib_list; *attr != None; attr += 2) {
if (attr[0] == GLX_ALPHA_SIZE) {
attr[1] = 0;
}
}
typeof(glXChooseFBConfig) *old_fbconfig;
old_fbconfig = dlsym(RTLD_NEXT, "glXChooseFBConfig");
return (*old_fbconfig)(dpy, screen, attrib_list, nelements);
}
__GLXextFuncPtr glXGetProcAddressARB(const GLubyte *name)
{
if (strcmp((const char *) name, "glXChooseFBConfig") == 0)
return glXChooseFBConfig;
typeof(glXGetProcAddressARB) *old_getproc;
old_getproc = dlsym(RTLD_NEXT, "glXGetProcAddressARB");
return (*old_getproc)(name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment