Sign in to follow this  
Spippo

SDL: Loading Image (bmp) from resource

Recommended Posts

I'm working with MS Visual Studio .NET 2003, and I made a new Visual Studio C++ Project (a empty win32 console project). SDL is working fine, and I'm getting my images at my screen, when I'm using the SDL_LoadBMP function. Now I want to use Images I included in my resource-file, but it doesn't work that well. I made this small function, to load an image out of a resource, but I still get a black screen, when I use it as a background. So it doesn't load the image, what am I doing wrong?
SDL_Surface* GetBitmap(int resID)
{
 SDL_Surface *image;

 HMODULE ownModuleHandle    = GetModuleHandle(NULL);
 HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(resID), RT_RCDATA);
 DWORD size = SizeofResource(ownModuleHandle,hrsrc);
 HGLOBAL hglob = LoadResource(ownModuleHandle,hrsrc);
 void *buf = LockResource(hglob);

 SDL_RWops *rw;
 rw = SDL_RWFromMem(buf, size);
 image = SDL_LoadBMP_RW(rw, 0);
 SDL_FreeRW(rw);
 return image;
}

Share this post


Link to post
Share on other sites
I did some checks after every step, and I noticed that i get the first error after

Quote:

HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(resID), RT_RCDATA);


If I change the RT_RCDATA to RT_BITMAP, I only get an error after:

Quote:

image = SDL_LoadBMP_RW(rw, 0);

(It returns a NULL pointer)

Anyone got an idea?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this