Help!!!
I have been trying to work with bitmaps with less than 8 bits per pixel without success. I have used glColorTable to implement the color lookup, and use glTexImage2D to specify the texture. 8 bit works fine with texType of GL_UNSIGNED_BYTE. However, for 4 bit and 1 bit I have tried using GL_BITMAP as the type with GL_COLOR_INDEX as the format but without success - basically the texture is black (completely black screen, as when either function errors it doesn’t map the texture to my objects and they show up as white having used glColorf(1.0,1.0,1.0).
I have searched the discussion groups for GL_BITMAP, but there was little information directly relevant. Also, there was a post in the beginner’s section but the 3 of us could come up with nothing and no one else volunteered anything.
So the question, is it possible to support < 8 bpp such that it uses a lookup table and that it recognizes that there is more than one pixel per byte? I would rather not convert the data into larger memory unless that is absolutely the only way. From the docs I have read within extension registry as well as the red book and blue book it seems it should be.
Below are the functions I use to get the resource and load it into GL. Please let me know if you see a solution or know of one.
void CglTexture::LoadBitmapResource(UINT id)
{
HRSRC Resource = (HRSRC)LoadResource(AfxGetInstanceHandle(), FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(id), MAKEINTRESOURCE(RT_BITMAP)));
unsigned char data = (unsigned char)LockResource(Resource);bmpInfo = (BITMAPINFO*)data;
colors = data + bmpInfo->bmiHeader.biSize;
pixels = colors + bmpInfo->bmiHeader.biClrUsed * sizeof(bmpInfo->bmiColors);GLenum format = GL_RGBA;
intFormat = GL_RGBA;switch (bmpInfo->bmiHeader.biBitCount)
{
case 0:
case 1:
intFormat = GL_COLOR_INDEX1_EXT;
texFormat = GL_COLOR_INDEX;
texType = GL_BITMAP;
break;
case 4:
intFormat = GL_COLOR_INDEX4_EXT;
texFormat = GL_COLOR_INDEX;
texType = GL_BITMAP;
break;
case 8:
intFormat = GL_COLOR_INDEX8_EXT;
texFormat = GL_COLOR_INDEX;
texType = GL_UNSIGNED_BYTE;
break;
case 16:
switch(bmpInfo->bmiHeader.biCompression)
{
case BI_BITFIELDS:
if (*(colors + 1) == 0x07E0)
{
texFormat = GL_RGB;
texType = GL_UNSIGNED_SHORT_5_6_5;
break;
}
case BI_RGB:
texFormat = GL_RGB5_A1;
texType = GL_UNSIGNED_SHORT_5_5_5_1;
break;
}
break;
case 24:
texFormat = GL_BGR;
texType = GL_UNSIGNED_BYTE;
intFormat = GL_RGB;
break;
case 32:
switch(bmpInfo->bmiHeader.biCompression)
{
case BI_RGB:
texFormat = GL_RGBA;
texType = GL_UNSIGNED_BYTE;
case BI_BITFIELDS:
texFormat = GL_RGBA;
texType = GL_UNSIGNED_BYTE;
}
break;
default:
texFormat = GL_RGB;
texType = GL_UNSIGNED_BYTE;
break;
}
if (texFormat == GL_COLOR_INDEX)
{
glEnable(GL_COLOR_TABLE);
glColorTable(texTarget, format, bmpInfo->bmiHeader.biClrUsed, GL_BGRA, texType, colors);
err = glGetError();
if (err)
DoError();
}
}void CglTexture::TexImage(int level)
{
glTexImage2D(texTarget, level, intFormat, bmpInfo->bmiHeader.biWidth, bmpInfo->bmiHeader.biHeight, 0, texFormat, texType, pixels);
err = glGetError();
if (err)
DoError();
}
Thanks,
Patrick