2

I want to use cairo in combination with glfw. There is absolutely no working document. And what is found does not compile. This is the best working example for glfw that I found:

#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);
    }
}

as you can see I have commented the line

#include <cairo/cairo-gl.h>

as it doesn't exist. But after playing with pkg-config libraries I reached this.

gcc cairogl.c `pkg-config --libs --cflags gl  glfw3  cairo`

This compiles, but of course some commands are unknown and I get linker errors too. What can I do for this? BTW, this all began from trying to render harfbuzz output in glfw, and there is no usable document, so I am trying to do the work using pango which works with harfbuzz and cairo.

genpfault
  • 51,148
  • 11
  • 85
  • 139
arashka
  • 1,226
  • 3
  • 17
  • 30

0 Answers0