[cairo] Cairo with OpenGL
freddie at witherden.org
Wed Dec 30 12:15:20 PST 2009
> I tried to follow the steps listed under "General approach". But i
> don't know which kind of cairo-surace to crate (maybe an image
> surface?). In addition i don't know how to copy the cairo-surface
> into an OpenGL-texture.
> I would be very glad if someone could help me with those two steps or
> if someone could tell me a link to the examples that works.
Yes, you want to use an image surface. Uploading to an OpenGL texture
is no different than uploading any other texture. Assuming you have an
void *bits = cairo_image_surface_get_data(cairo_get_target(cr));
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height, 0,
GL_BGRA, GL_UNSIGNED_BYTE, bits);
Of course, if you are targeting OpenGL 2.1+ or have power-of-two
textures then you do not need to use GL_TEXTURE_RECTANGLE_ARB :)
Performance is satisfactory, so long as you do not redraw the surface
every frame (caching is important).
More information about the cairo