SDL: Loading Image (bmp) from resource

Started by
0 comments, last by Spippo 17 years, 11 months ago
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;
}
Spippo is magic,is magic!!!!!Oh ho hoo!!!!Spippo is magic
Advertisement
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?
Spippo is magic,is magic!!!!!Oh ho hoo!!!!Spippo is magic

This topic is closed to new replies.

Advertisement