Advertisement

lesson 38 resource file questions

Started by July 21, 2003 08:00 PM
2 comments, last by nitzan 21 years, 7 months ago
I want my program to be able to check if a bitmap is in the resource file, then if it is, load it from the resource file, if its not, load the bitmap normally. i.e. I call loadBMP with "data/crate.bmp" loadBMP looks at the filename, and checks for an ID with a similiar name, like "IDB_CRATE", then if it exists, retrieve it from the resource file. If it does not, it loads crate.bmp. Any ideas how to do this ? Nitzan
Use the LoadImage() API function, it returns a handle of an image in a resource file, then all you have to do is test if it is a valid handle, if not then load from disk, ie:

// get filename to load
// call LoadImage() (taken from win32 api helpfile):
HANDLE LoadImage(
HINSTANCE hinst, // handle of the instance that contains the image
LPCTSTR lpszName, // name or identifier of image
UINT uType, // type of image
int cxDesired, // desired width
int cyDesired, // desired height
UINT fuLoad // load flags
);
// check if handle is ok then load bitmap from file if it isn''t, or just proceed if it''s ok, as you''ve got the handle there.

--
Cheers,
--
Cheers,
Darren Clark
Advertisement
Thanks! Now I have a new question...

every time I call either
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

or

glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);

my program crashes. Even when I copy the code exactly from Lesson 38 ( and rename the IDB tags) it crashes at the gluBuild2DMipmaps() call. Any ideas why this is happening ? BMP seems to be valid (bmWidth and bmHeight return values and bmBits is non zero).

Nitzan


Ok, apparently the problem was the bitmap was only 256 colors. How do I load a bitmap that is only 256 colors from the resource file ?

Thanks,

Nitzan

This topic is closed to new replies.

Advertisement