[cairo] Cairo with OpenGL
Freddie Witherden
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
ARGB32 surface:
void *bits = cairo_image_surface_get_data(cairo_get_target(cr));
cairo_surface_flush(cairo_get_target(cr));
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureId);
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).
Regards, Freddie.
More information about the cairo
mailing list