Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render cairo surface directly to OpenGL texture

Tags:

c++

opengl

cairo

I'm using cairo (http://cairographics.org) in combination with an OpenGL based 3D graphics library.
I'm currently using the 3D library on Windows, but I'm hoping to receive an answer that is platform independent. This is all done in c++.

I've got the straight forward approach working which is to use cairo_image_surface_create in combination with glTexImage2D to get an OpenGL texture.

However, from what I've been able to gather from the documentation cairo_image_surface_create uses a CPU-based renderer and writes the output to main memory.

I've come to understand cairo has a new OpenGL based renderer which renders its output directly on the GPU, but I'm unable to find concrete details on how to use it.
(I've found some details on the glitz-renderer, but it seems to be deprecated and removed).

I've checked the surface list at: http://www.cairographics.org/manual/cairo-surfaces.html, but I feel I'm missing the obvious.

My question is: How do I create a cairo surface that renders directly to an OpenGL texture?
Do note: I'll need to be able to use the texture directly (without copying) to display the cairo output on screen.

like image 983
Remco Avatar asked May 24 '11 09:05

Remco


1 Answers

As of 2015, Cairo GL SDL2 is probably the best way to use Cairo GL

https://github.com/cubicool/cairo-gl-sdl2

If you are on an OS like Ubuntu where cairo is not compiled with GL you will need to compile your own copy and let cairo-gl-sdl2 know where it is.

like image 190
Stuart Axon Avatar answered Sep 21 '22 15:09

Stuart Axon