hey, this is my first time here, and I think you might like to know that i am the n00biest of all n00bs. Anyway, I''ve been programming this little cube with a bitmap texture as a win32 resource in msvc++ 6. My problem is, I can''t get the transparency to work. Heres my LoadGLTextures:
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
HWND hwnd;
int Status=TRUE; // Status Indicator
// load bitmap from resource file
HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP2));
// setup 24 bits bitmap structure
// works on 8 bits bitmaps also!
BITMAPINFO info;
BITMAPINFOHEADER header;
header.biSize = sizeof(BITMAPINFOHEADER);
header.biWidth = 256;
header.biHeight = 256;
header.biPlanes = 1;
header.biBitCount = 24;
header.biCompression = BI_RGB;
header.biSizeImage = 0;
header.biClrUsed = 0;
header.biClrImportant = 0;
info.bmiHeader = header;
info.bmiColors->rgbRed = NULL;
info.bmiColors->rgbGreen = NULL;
info.bmiColors->rgbBlue = NULL;
info.bmiColors->rgbReserved = NULL;
// store bitmap data in a vector
const int size = 256*256*3;
unsigned char data[size];
HDC hdc = GetDC(hWnd);
GetDIBits(hdc, bitmap, 0, 256, &data, &info, DIB_RGB_COLORS);
ReleaseDC(hWnd, hdc);
// convert from BGR to RGB
unsigned char buff;
for(int i=0; i<256*256; i++)
{
buff = data[i*3];
if(i>=3)
{
data[i*3] = data[i*3+2];
data[i*3+2] = buff;
}
}
unsigned char *src_bitmap = data;
unsigned char *alpha_bitmap = (unsigned char *)malloc(((256)*(256)) *4) ;
for (unsigned int src = 0, dst = 0; src < (256)*3; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.
if( src_bitmap[src] == 0xFF && src_bitmap[src+1] == 0 && src_bitmap[src+2] == 0xFF )
{
alpha_bitmap[dst+3] = 0;
PostQuitMessage(0); //I tell it to quit, and it WONT!
}
else
alpha_bitmap[dst+3] = 0xFF;
// copy pixel data over
alpha_bitmap[dst] = src_bitmap[src];
alpha_bitmap[dst+1] = src_bitmap[src+1];
alpha_bitmap[dst+2] = src_bitmap[src+2];
}
// create one texture
glGenTextures(1, &m_texture[0]);
// select texture
glBindTexture(GL_TEXTURE_2D, m_texture[0]);
// SetTextureParameters
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 256, 256,
GL_RGBA, GL_UNSIGNED_BYTE, alpha_bitmap);
// generate texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, &data);
//free all the stuff, etc.
and within my DrawScene(), i have:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);
right before i draw my cube. My cube''s texture has a large pink(255,0,255) square on it that should go transparent, but it doesn''t. Help me, please.
Thank you all!
http://www.WoodmanStudios.tk