Advertisement

Newbie: Loading a Resource in Win

Started by January 05, 2002 03:56 PM
3 comments, last by RichGould77 23 years, 1 month ago
I am trying to use NeHe’s Bitmap loading code to load a bitmap resource in MSVC++. Here is my code: HBITMAP hbmMyImage; hbmMyImage = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)); if(hbmMyImage == NULL){ MessageBox(0, "It didn''t work.", "Oh oh.", MB_OK); } AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Textures memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL if (TextureImage[0] = hbmMyImage) { glGenTextures(1, &Texture[0]); // Create Five Textures glBindTexture(GL_TEXTURE_2D, Texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); } if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data);// Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure } I get one error, one this line: if (TextureImage[0] = hbmMyImage) the error is: error C2440: ''='' : cannot convert from ''struct HBITMAP__ *'' to ''struct _AUX_RGBImageRec *'' I understand what it means, but I don’t know how to correct it, any idea? Thanks Richard =/\=
Richard =/=
hey

what you are doing is assigning an object of type_1 to a different object of type_2: a HBITMAP to a pointer to _AUX_RGBImageRec. the simplest way to put it is - you can''t do that.

if you''re meaning to COMPARE them, you should use ==, but that wouldn''t make much difference - you cant compare objects of two different types. my question is: why would you need to compare them at all?? or WAS it you intention to assign one to the other?

you should use the bitmap loading code from NeHe''s tutes (7) and you should get the code working w/o problems by just removing the if statement. i trust you didn''t find this in NeHe''s tutorials

bottom line - you don''t use HBITMAP in opengl, at least not here. HBITMAP is for Win32 API and there is should remain...

keep cool
Advertisement
I''m guessing you thought that assignment would return TRUE if successful - sorry.

The correct way to get the bitmap data would be to use the function GetDIBits. You won''t ever need to use aux_RGBImageRec because you''re using Windows to load your bitmaps, not glaux.

If you want more info on GetDIBits, see this page:
http://www.piclist.com/techref/os/win/api/win32/func/src/f30_14.htm

Make sure to read up on BITMAPINFO and BITMAPINFOHEADER too, since you''ll need them.
I understand that this code is all wrong, and I knew that I was trying to change one struct into another, but I don't know how I can fix it.

Looking at that link, it seems that making a resource into a openGL texture is a complicated process, can you post any more code that might help me? or show me how to use the functions you just mentioned?

thanks
Richard =/\=

Edited by - RichGould77 on January 6, 2002 6:02:07 AM
Richard =/=
Okay, let me break it down. The steps you need to follow are:

1. Load the bitmap and obtain an HBITMAP for it. Accomplished by LoadBitmap.
2. Dump the raw information (the RGB values) where you can access it. Accomplished with GetDIBits.
3. Use the raw information to create a texture. Accomplished with all the glTex calls.

You already have steps one and three.

To do the 2nd step:
  BITMAPINFO bi;void * rawbits;//LoadBitmap call goes here...//This fills the BITMAPINFO structure for youbi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);GetDIBits(hDC, hbmMyImage, 0, 0, NULL, &bi, DIB_RGB_COLORS);//Allocate the needed memoryrawbits = (void *)new char[bi.bmiHeader.biSizeImage];//This will actually copy the bits to the new bufferGetDIBits(hDC, hbmMyImage, 0, bi.bmiHeader.biHeight, rawbits, &bi, DIB_RGB_COLORS);//Now proceed with your gl calls, except replace your glTexImage2d call with this:glTexImage2D(GL_TEXTURE_2D, 0, 3, bi.bmiHeader.biWidth, bi.bmiHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, rawbits);  



Note that that will only work for bitmaps that are already 24-bit RGB bitmaps. There''s a way to convert other bitmaps on the fly right here but it takes a bit of extra work. Note also that the loaded texture *may* be upside down.

This topic is closed to new replies.

Advertisement