Skip to content

Instantly share code, notes, and snippets.

@tobyp
Created July 22, 2016 15:53
Show Gist options
  • Save tobyp/53fbf1bdff40bbda8f2509a73821f07e to your computer and use it in GitHub Desktop.
Save tobyp/53fbf1bdff40bbda8f2509a73821f07e to your computer and use it in GitHub Desktop.
Minimal test program to reproduce a GLFW/Cairo problem concerning GLX
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_GLX
#include <GLFW/glfw3native.h>
#include <cairo/cairo.h>
#include <cairo/cairo-gl.h>
#include <stdlib.h>
int main(int argc, char * argv[]) {
glfwInit();
// changes nothing on 3.2
// glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
GLFWwindow * window = glfwCreateWindow(800, 600, "Test", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
Display * x11_display = glfwGetX11Display();
GLXContext glx_context = glfwGetGLXContext(window);
Window x11_window = glfwGetX11Window(window);
cairo_device_t * cairo_device = cairo_glx_device_create(x11_display, glx_context);
cairo_surface_t * cairo_surface = cairo_gl_surface_create_for_window(cairo_device, x11_window, 800, 600);
cairo_device_destroy(cairo_device);
cairo_t * ctx = cairo_create(cairo_surface);
while (!glfwWindowShouldClose(window)) {
cairo_set_source_rgb(ctx, 1.0, 0.0, 0.0);
cairo_paint(ctx);
cairo_gl_surface_swapbuffers(cairo_surface);
glfwSwapBuffers(window);
glfwPollEvents();
glfwSetWindowShouldClose(window, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment