PDA

View Full Version : Loading a bitmap to a texture



MACCERS
11-29-2002, 01:50 AM
Can someone tell me way there is an access violation here:

HBITMAP i = DibSectionPieceWise(3);
BITMAP texture1;
// if (!texture1) exit(1);
// Create Texture
::GetObject( i, sizeof( texture1 ), &texture1 );


glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1.bmWidth, texture1.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1.bmBits);

MACCERS
11-29-2002, 05:57 AM
sorry I should have said it was to do with the texture1.bmBits?



Originally posted by MACCERS:
Can someone tell me way there is an access violation here:

HBITMAP i = DibSectionPieceWise(3);
BITMAP texture1;
// if (!texture1) exit(1);
// Create Texture
::GetObject( i, sizeof( texture1 ), &texture1 );


glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1.bmWidth, texture1.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1.bmBits);

Relic
11-29-2002, 08:44 AM
Read the BITMAPINFOHEADER manual on MSDN.
Multiple things can go wrong here.
- You're sure you need unpack alignment of 4, not 1?
- Texture size needs to be power of two.
- texture1.biBitcount needs to be 24.
- texture1.biCompression must be BI_RGB (uncompressed).
- bmHeight can be negative!