Advertisement

Bitmaps from resource scripts?

Started by January 12, 2001 08:57 PM
9 comments, last by MrSandman666 24 years ago
I use OpenGL to display some bitmaps and the OpenGL part works fine as long as I load the bitmaps the conventional way: from a *.bmp file. If I include the same bitmaps in a resource script and try to load them then the bitmap dimensions are correct but the bitmap data is empty. This is the code I use:
  
BITMAP bm;
	GetObject(LoadBitmap(hInst, MAKEINTRESOURCE(FLARE)), sizeof( bm ), &bm);

	glGenTextures(1, &Image);
			
	// select the texture object

	glBindTexture(GL_TEXTURE_2D, Image);

	// Generate The Texture 

	glTexImage2D(GL_TEXTURE_2D, 0, 3, bm.bmWidth, bm.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bm.bmBits);
  
As I said, the size is read correctly but bm.bmBits is just empty. Any ideas? "Mr Sandman bring me a dream"
-----------------------------"Mr Sandman bring me a dream"
Instead of using LoadBitmap, try using LoadImage. That solved the problem I had the last time I ran into troubles with bitmaps.

HBITMAP hBM = LoadImage(hInst, MAKEINTRESOURCE(IDB_BM), IMAGE_BITMAP, 0,0, LR_DEFAULTSIZE);



==========================================
In a team, you either lead, follow or GET OUT OF THE WAY.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
I''m afraid that didn''t change a thing. Still the same problem: dimensions are correct but there is no data in bm.bmBits

"Mr Sandman bring me a dream"
-----------------------------"Mr Sandman bring me a dream"
Check to see if hInst is valid. That could be the problem... but it''s a long shot.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
What do you mean: Check hInst? I take directly from where it''s passed to WinMain:
  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){	hInst = hInstance;  

how can THAT not be invalid? And anyways, how do I check whether it''s valid?


"Mr Sandman bring me a dream"
What do you mean: Check hInst? I take directly from where it''s passed to WinMain:
  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){	hInst = hInstance;  

how can THAT not be invalid? And anyways, how do I check whether it''s valid?


"Mr Sandman bring me a dream"
-----------------------------"Mr Sandman bring me a dream"
Advertisement
I can''t remember precisely, but I think you have to ask for a DIBSECTION, not a BITMAP to get the bmBits member filled, and also the bitmap should be a DIB, you can specify this when you load it (LR_CREATEDIBSECTION).
Well, no I have some Data, thanx TwoFlower. The only problem is is that the data is completely screwed up. The images are just some scrambled random trash that doesn''t lool like the image in the resource editor at all. Any ideas?

"Mr Sandman bring me a dream"
-----------------------------"Mr Sandman bring me a dream"
That''s probably because a DIB is a device independent bitmap (probably stored as 24bit). You will need to convert it to the same format as the display.
I know next to nothing about OpenGL so I don''t know if this is true or not.
Hmmm, I followed your hint about the colors and I discovered something interesting:
It works when I leave the image at 16 bit but as the images are only black and white I usualy convert them to greyscale. But as soon as I get the color depth lower than 16 bits, everything gets screwed. This was not the case when I loaded the bitmaps directly from the *.bmp file. Does anybody know a way to work auround that? I have no idea what to do here.

"Mr Sandman bring me a dream"
-----------------------------"Mr Sandman bring me a dream"

This topic is closed to new replies.

Advertisement