Hi there, I've been following a tutorial from
here.
However I'm having trouble loading PNG images, .bmp works fine, the code I have so far is:
SDL_Surface *Graphics::load_image(char *resfilename, char *imgfilename) {
// Get the images buffer and size from the resource file
int filesize = 0;
char *buffer = get_buffer_from_resource(resfilename, imgfilename, &filesize);
// Load the buffer into a surface using RWops
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
SDL_Surface *temp = IMG_Load_RW(rw, 1);
// Release the image buffer memory
free(buffer);
// Were we able to load the image?
if(temp == NULL) {
std::cout << "Unable to load image: " << SDL_GetError();
exit(1);
}
// Convert the image to optimal display format
g_Image = SDL_DisplayFormatAlpha(temp);
// Free the temp surface
SDL_FreeSurface(temp);
return g_Image;
}
I've tried:
SDL_Surface *temp = IMG_LoadTyped_RW(rw, 1, "PNG");
but no luck. The stdout.txt file reads, "Unable to load image: Error reading the PNG file."
Any ideas/tips will be appreciated, thanks.