PDA

View Full Version : problem with loading textures from a resource VC++



GW
08-31-2001, 12:36 PM
I've made some progress from my previous post. Now I can get the texture of a sky to load, but the texture is all green with white clouds instead of blue with white clouds. The texture is 256x256. Any help would be greatly appreciated. Here is what I'm doing:

BITMAPINFO* pBitmapInfo = NULL;
HINSTANCE hInst = AfxGetResourceHandle();

HRSRC hRsrc = FindResource(hInst, MAKEINTRESOURCE(IDB_SKY), RT_BITMAP);

ASSERT(hRsrc);

BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);

ASSERT(lpRsrc);

pBitmapInfo = (BITMAPINFO *)LockResource(lpRsrc);

if (pBitmapInfo)
{
glGenTextures(1, &m_textures[0]);
glBindTexture(GL_TEXTURE_2D, m_textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBitmapInfo);
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, 256, 256, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBitmapInfo);
}

Korval
08-31-2001, 05:13 PM
A BITMAPINFO structure is defined as follows:

typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

That BITMAPINFOHEADER is a header. OpenGL isn't processing your header information. So, it will assume it's part of the texture. That will result in some garbage being displayed.

Also, notice that the texture is stored in RGBQUAD structures. As you may be able to guess from the name, these store 4 bytes per entry. The 4-th byte is unused and is probably there for alignment purposes.

You should read out the bitmap information from the BITMAPINFO structure into a simple array of RGB color values, which you then pass to gluBuild2DMipmaps.

GW
09-04-2001, 10:40 AM
Thank you for the help!