Im trying to draw a svg to a SDL_Surface with this library:
This is my current code:
extern void nsvg_drawSVGtoSDLSurface(const char *svg_file, SDL_Surface *surface){
NSVGimage *image;
NSVGrasterizer *rast;
unsigned char *img;
int w, h;
image = nsvgParseFromFile(svg_file,"px", 96.0F);
if(image == NULL){
printf("Image not found.\n");
goto failing;
}
w = (int)image->width;
h = (int)image->height;
rast = nsvgCreateRasterizer();
if(rast == NULL){
printf("Rasterizer could not be initialized.\n");
goto failing;
}
img = malloc(w*h*4);
if(img == NULL){
printf("Image buffer could not be allocated.\n");
goto failing;
}
nsvgRasterize(rast, image, 0, 0, 1, img, w, h, w*4);
surface = SDL_CreateRGBSurfaceFrom(img, w , h, 32, 1920, 0, 0, 0, 0);
if(surface == NULL){
printf("Failed to create a surface: %s", SDL_GetError());
goto failing;
}
SDL_LockSurface(surface);
free(img);
failing:
nsvgDeleteRasterizer(rast);
nsvgDelete(image);
}