Sign in to follow this  

SDL: Loading Image (bmp) from resource

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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