Skip to main content
gamedev.net
🔒 Locked

SDL: loading bitmap from resource

Started by Gaskocher Feb 22, 2005 at 5:12 AM 0 replies 1k views
Original Post
Gaskocher
Gaskocher
Hello everybody, I took the SDL tutorial by Marius Andra as a base for my own project but I want to load the Bitmaps from a resource. As far as I can tell by debugging everything works well but in CSpriteBase SDL_LoadBMP_RW() returns NULL. The errormessage says: File is not a Windows BMP file Anyone got an idea? I am using SDL1.2.8lib You can download the src from: http://81.169.135.33/~dw/fish.zip thanks in advance!

SDL_Surface* CSpriteBase::getImageFromRessource(const int resID, LPCTSTR type)
{
	SDL_RWops *tmp;
	HRSRC hres;
	HGLOBAL hnd;
	int rsz;
	tmp = NULL;
	SDL_Surface *srf = NULL;

	hres = FindResource(NULL, MAKEINTRESOURCE(resID), type);
	//hres = FindResource(NULL, MAKEINTRESOURCE(resID), RT_BITMAP);

	if (hres)
		hnd = LoadResource(NULL, hres);
	else
	{
		fprintf(stderr, "Can't load image from resource : %s\n", SDL_GetError());
	}
	if (hnd)
	{
		hnd = LockResource(hnd);

		if (!hnd)
		{
			fprintf(stderr, "Can't load image from resource : %s\n", SDL_GetError());
		}
		else
		{
			rsz = SizeofResource(NULL, hres);

			if (!rsz)
			{
				fprintf(stderr, "Can't load image from resource : %s\n", SDL_GetError());
			}
		}
	}
	else
	{
		fprintf(stderr, "Can't load image from resource : %s\n", SDL_GetError());
	}
	tmp = SDL_RWFromMem(hnd, rsz);
	//srf = IMG_Load_RW(tmp, 1);
	srf = SDL_LoadBMP_RW(tmp, 1);
	if (srf == NULL)
		fprintf(stderr, "Can't load image from resource : %s\n",
		SDL_GetError());

	//SDL_FreeRW(tmp);
	DeleteObject(hnd);
	return srf;
}
[Edited by - Gaskocher on February 22, 2005 5:34:40 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.