Skip to content

Instantly share code, notes, and snippets.

@whitequark
Last active March 25, 2018 13:42
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 whitequark/27831e23414a1f44b47c9341ffff7cde to your computer and use it in GitHub Desktop.
Save whitequark/27831e23414a1f44b47c9341ffff7cde to your computer and use it in GitHub Desktop.
gcc -lGL -lX11 glinfo.c -o glinfo && ./glinfo
#include <GL/gl.h>
#include <GL/glx.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
Display *dpy = XOpenDisplay(NULL);
if(!dpy) {
puts("cannot XOpenDisplay");
return 1;
}
int scrnum = DefaultScreen(dpy);
Window root = RootWindow(dpy, scrnum);
int attrib[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo *visinfo = glXChooseVisual(dpy, scrnum, attrib);
if(!visinfo) {
puts("cannot get an RGB, double-buffered visual");
return 1;
}
XSetWindowAttributes attr;
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Window win = XCreateWindow(dpy, root, 0, 0, 100, 100,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
GLXContext ctx = glXCreateContext(dpy, visinfo, NULL, True);
if(!ctx) {
puts("cannot glXCreateContext");
return 1;
}
glXMakeCurrent(dpy, win, ctx);
int max_texture_size;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
printf("glGetIntegerv(GL_MAX_TEXTURE_SIZE) = %d\n", max_texture_size);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment