PDA

View Full Version : loading bitmaps from resources in VC++



GW
08-29-2001, 12:27 PM
I'm trying to load my textures from bitmaps I put in my resources and I'm having trouble. I'm trying the following:

CBitmap Bitmap;
LPVOID lpBitmap;
BITMAP bm;
DWORD dwBitmapSize;

Bitmap.LoadBitmap(IDB_SKY);
Bitmap.SetBitmapDimension(128,128);
Bitmap.GetObject(sizeof(bm), &bm);
dwBitmapSize=bm.bmHeight*bm.bmWidthBytes * bm.bmPlanes;
Bitmap.GetBitmapBits(dwBitmapSize, lpBitmap);

glGenTextures(1, &m_textures[0]);

glBindTexture(GL_TEXTURE_2D, m_textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);

Any tips on what I'm doing wrong?

DFrey
08-29-2001, 01:09 PM
I'm assuming the bitmap resource's original size is 128 by 128 correct?

kistompika
08-29-2001, 01:09 PM
What's the problem exactly? Do you use 24bit BGR bitmap resources?

GW
08-29-2001, 02:20 PM
Originally posted by DFrey:
I'm assuming the bitmap resource's original size is 128 by 128 correct?

Yes the bitmap is 128x128. Actually I removed that function call since it seems unnecessary.

The problem is that I get an "Unhandled Exception 0xC0000005: Access Violation" on

glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);

The call stack shows:
NVOGLNT! DrvSetPixelFormat + 468892 bytes