SDL_LoadBMP_RW gives empty surface?

Hello, I’ve been messing around with loading images from the win32 .exe
resources.
However, for some reason the surface stays empty and doesnt show anything
when i place it on the screen.

Some bits of the code:-----------------------------------
SDL_Surface *image;

HMODULE ownModuleHandle = GetModuleHandle(NULL);
HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(BITMAP1),
RT_BITMAP);
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);


The size of the resource (retreived with SizeofResource) matches the size of
the .BMP file in the resources, so I assume it is loaded correctly.
None of the hrsrc, size, hglob and buf variables are NULL (IF-statements
that check this are omitted from the code)

Can anyone tell me what I’m doing wrong?

Thanks,
F. de Vries.

followup:
the variable image turns out to be NULL, and the error returned by
SDL_LoadBMP_RW is “File is not a Windows BMP file”.
The file in the resources .is. however a valid windows BMP file.

any thoughts?
thanks

“F. de Vries” <@F_de_Vries> wrote in message
news:e40066$vi5$1 at sea.gmane.org…> Hello, I’ve been messing around with loading images from the win32 .exe

resources.
However, for some reason the surface stays empty and doesnt show anything
when i place it on the screen.

Some bits of the code:

SDL_Surface *image;

HMODULE ownModuleHandle = GetModuleHandle(NULL);
HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(BITMAP1),
RT_BITMAP);
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);


The size of the resource (retreived with SizeofResource) matches the size
of the .BMP file in the resources, so I assume it is loaded correctly.
None of the hrsrc, size, hglob and buf variables are NULL (IF-statements
that check this are omitted from the code)

Can anyone tell me what I’m doing wrong?

Thanks,
F. de Vries.

Moving the BMP resource from the default folder for bitmaps to the folder
"RC_DATA" somehow did the trick.
Can’t see why the contents of the resource would change if it’s placed under
a different type, but whatever.

Cheers.

“F. de Vries” <@F_de_Vries> wrote in message
news:e4018v$3op$1 at sea.gmane.org…> followup:

the variable image turns out to be NULL, and the error returned by
SDL_LoadBMP_RW is “File is not a Windows BMP file”.
The file in the resources .is. however a valid windows BMP file.

any thoughts?
thanks

“F. de Vries” <@F_de_Vries> wrote in message
news:e40066$vi5$1 at sea.gmane.org

Hello, I’ve been messing around with loading images from the win32 .exe
resources.
However, for some reason the surface stays empty and doesnt show anything
when i place it on the screen.

Some bits of the code:

SDL_Surface *image;

HMODULE ownModuleHandle = GetModuleHandle(NULL);
HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(BITMAP1),
RT_BITMAP);
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);


The size of the resource (retreived with SizeofResource) matches the size
of the .BMP file in the resources, so I assume it is loaded correctly.
None of the hrsrc, size, hglob and buf variables are NULL (IF-statements
that check this are omitted from the code)

Can anyone tell me what I’m doing wrong?

Thanks,
F. de Vries.

Moving the BMP resource from the default folder for bitmaps to the folder
"RC_DATA" somehow did the trick.
Can’t see why the contents of the resource would change if it’s placed under
a different type, but whatever.
Hi,

I’m guessing that you’re using an IDE, so I don’t know what you mean by
’“RC_DATA” folder’ but:

Resources, stuff like icons, dialog templates, menus, bitmaps, binary objects,
etc. are described in a .rc file something like this:


IDB_TOOLBAR BITMAP DISCARDABLE “image.bmp” // bitmap
ICO_ICON1 ICON DISCARDABLE “app.ico” // icon
IDM_BITMAP RCDATA // blob
BEGIN
#include "image.bmp.blob"
END

When a bitmap is included using the BITMAP directive, the resource
compiler ingeniously removes the BITMAPFILEHEADER off the front of the
file. This is the bit that that starts ‘BM’, and has the file size and
an offset to the data in, and is probably what SDL_LoadBMP_RW() is
upset about.

If RCDATA is used (which has probably got something to do with the
RC_DATA folder you mention above), then the whole thing is included,
untouched, as a blob.

With the resource compiler and tools I’m using, RCDATA won’t just use
the contents of a file, but insists on the data being in-place as
strings or hex, so I use a tiny Python script to generate an
intermediate .blob file which I then include.

Hope that helps,

cheers,
John.On Fri, May 12, 2006 at 01:09:07AM +0200, F. de Vries wrote:

Cheers.

“F. de Vries” wrote in message
news:e4018v$3op$1 at sea.gmane.org

followup:
the variable image turns out to be NULL, and the error returned by
SDL_LoadBMP_RW is “File is not a Windows BMP file”.
The file in the resources .is. however a valid windows BMP file.

any thoughts?
thanks

“F. de Vries” wrote in message
news:e40066$vi5$1 at sea.gmane.org

Hello, I’ve been messing around with loading images from the win32 .exe
resources.
However, for some reason the surface stays empty and doesnt show anything
when i place it on the screen.

Some bits of the code:

SDL_Surface *image;

HMODULE ownModuleHandle = GetModuleHandle(NULL);
HRSRC hrsrc = FindResource(ownModuleHandle, MAKEINTRESOURCE(BITMAP1),
RT_BITMAP);
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);


The size of the resource (retreived with SizeofResource) matches the size
of the .BMP file in the resources, so I assume it is loaded correctly.
None of the hrsrc, size, hglob and buf variables are NULL (IF-statements
that check this are omitted from the code)

Can anyone tell me what I’m doing wrong?

Thanks,
F. de Vries.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl