[cairo] Loading a SVG file and displaying it on SDL
André Wagner
andre.nho at gmail.com
Fri Mar 9 06:15:25 PST 2007
Hello!
I'm trying to load a SVG file and show it in a SDL window using cairo. This is my code:
RsvgHandle* h;
int width = 500;
int height = 500;
int stride = width * 4;
unsigned char* cairo_data =
(unsigned char *) calloc(stride * height, 1);
cairo_surface_t *cairo_surface =
cairo_image_surface_create_for_data(cairo_data,
CAIRO_FORMAT_ARGB32, width,
height, stride);
cairo_t *cr = cairo_create(cairo_surface);
cairo_save(cr);
cairo_scale(cr, width, height);
cairo_set_source_rgba(cr, 1, 1, 1, 1);
cairo_paint(cr);
GError* e = NULL;
h = rsvg_handle_new_from_file("closedbox.svg", &e);
if(e != NULL)
exit(1);
rsvg_handle_render_cairo(h, cr);
SDL_Surface* sf;
sf = SDL_CreateRGBSurfaceFrom((void *) cairo_data, width,
height, 32, stride, 0x00ff0000, 0x0000ff00,
0x000000ff, 0xff000000);
SDL_BlitSurface(sf, NULL, screen, NULL);
SDL_UpdateRect(screen, 0, 0, 0, 0);
cairo_destroy(cr);
What am I doing wrong? It displays a white window, so I know (suppose) the transference from cairo to SDL is working. It seems the SVG image I loaded using librsvga is not showing on my cairo surface.
I'm not very skilled with cairo or librsvga, so I might just have a stupid mistake.
I'm using Win32, BTW (I hope this isn't the stupid mistke ;-)
Best regards,
André
--
A cura para o tédio é a curiosidade.
Não há cura para a curiosidade. (Dorothy Parker)
More information about the cairo
mailing list