Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Getting a PNG image from a resource file

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 Toshio   Members   

135
Like
0Likes
Like

Posted 30 March 2012 - 08:48 AM

Hello. I got this one problem I need to solve, and it's putting and getting a PNG image from a resource file.
I followed these two tutorials: http://content.gpwik..._Resource_Files and http://content.gpwik...sing_SDL_RWops.
Bitmaps work, but I can't get PNGs on the screen.

This is the code I thought would work for loading an image from a resource file:

SDL_Surface* CSurface::load_image(char *resource, char *File )
{
	int filesize = 0;
	char *buffer = GetBufferFromResource(resource, File, &filesize);
	SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
	SDL_Surface *loadedImage = IMG_LoadPNG_RW(rw);
	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;
	free(buffer);
	//If the image loaded
	if( loadedImage != NULL )
	{
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat( loadedImage );
		//Free the old image
		SDL_FreeSurface( loadedImage );
	}
	//Return the optimized image
	return optimizedImage;
}

... but it doesn't work.

I didn't touch the code from the tutorial where it creates a resource file, so that might be the problem.

#2 szymczyk   Members   

182
Like
0Likes
Like

Posted 30 March 2012 - 12:31 PM

Are you using SDL_image? SDL can load BMP files but not PNG files. You need to use SDL_image to be able to load PNG files.

If you are using SDL_image on Windows, the Windows version comes with DLLs for different image formats. The DLL for PNG files needs to be in the same location as the SDL and SDL_image DLLs or you won't be able to load PNG files.
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com

#3 Toshio   Members   

135
Like
0Likes
Like

Posted 30 March 2012 - 12:44 PM

Yes, I am using SDL_image. You can even see me using the command IMG_LoadPNG_RW().
I have all the necessary DLLs files in the folder where my game is.
I can blit PNGs when loading them normally, but it doesn't work when trying to load them from the resource file.

#4 Toshio   Members   

135
Like
0Likes
Like

Posted 31 March 2012 - 03:36 PM

Anyone? Posted Image




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.