The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Using images from executable resources
Pavgran


Joined: 15 Oct 2013
Posts: 1
Helllo!

I'm using SDL 1.2 and Windows.
I'm searching for the way to build images in my game into executable. Sadly, I haven't found how to use this images in the SDL functions.
Inded, I found a part of the solution, but it involved monstrouos code with low-level copying of image data from HBITMAP structure to SDLSurface.
So, is there some elegant way t do this, perhaps using any library or undocumented functions?

Thanks!
Hjorthenify


Joined: 10 Jan 2014
Posts: 1
What I do is that I save the resource as a RC data instead of a bitmap, as doing so will remove the bitmap header, which causes Load_RW to read nothing but garbage. Adding it as a RC data resource instead of a bitmap fixes this problem. I then use the window library to recieve the data as an array of data which I then passes to Load_RW. Here's the function I use:
Code:

TEXPTR CFilesystem::LoadTextureFromResource(LPCWSTR resname)
{   
   
   SDL_Surface * bitmapSurface = NULL;

   TEXPTR rtexture = NULL;
   HRSRC resPos = NULL;
   HMODULE ins = NULL;
   HGLOBAL res = NULL;
   DWORD resLenght = NULL;
   LPVOID resStream = NULL;
   SDL_RWops * memdat = NULL;


   ins = GetModuleHandle(0);
   resPos = FindResource(ins, resname, RT_RCDATA);
   res = LoadResource(ins, resPos);
   resStream = LockResource(res);
   resLenght = SizeofResource(ins, resPos);
   

   memdat = SDL_RWFromConstMem(resStream, resLenght);

   if((bitmapSurface = IMG_Load_RW(memdat, 0))==NULL)
      MessageBoxA(NULL, SDL_GetError(), "ERROR", NULL);

   
   rtexture = ConvertSurfaceToTexture(bitmapSurface);
   SDL_FreeSurface(bitmapSurface);
   Textures[resname] = rtexture;

   return rtexture;

}