PDA

View Full Version : more problems with ALPHA_TEST



silicon_chipper
09-09-2006, 03:31 PM
Sorry. I changed a bmp from RGB to RGBA. If the red, green, and blue values were all zero I set the pixel's alpha value to 0 otherwise I set it 255. I made it a texture and called glEnable(GL_ALPHA_TEST) and glAlphaFunc(GL_GREATER, 0.5f). It is a blue square on a white background. I then rendered the texture onto a quad and the white background remained. What can be the problem? Can anyone help?


bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

BMPClass bmp;
BMPLoad(fileName,bmp);


unsigned char* texels = new unsigned char[bmp.width*bmp.height*4];
unsigned char* outTexel = texels;
unsigned char* inTexel = bmp.bytes;
for( int y = 0; y < bmp.height; y++ )
{
for( int x = 0; x < bmp.width; x++, inTexel += 3, outTexel += 4 )
{
int r = inTexel[0];
int g = inTexel[1];
int b = inTexel[2];
int a;
if(r==0&amp;&amp;g==0&amp;&amp;b==0)
{
a = 0;
}
else
{
a=255;
}
outTexel[0] = r;
outTexel[1] = g;
outTexel[2] = b;
outTexel[3] = a;
}
}


glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp.width,bmp .height,0,GL_RGBA,GL_UNSIGNED_BYTE,texels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glEnable(GL_TEXTURE_2D);

return true;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);

glEnable (GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,.5f);

glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex3d(-1.33,-1,-2);
glTexCoord2d(0,1); glVertex3d(-1.33,1,-2);
glTexCoord2d(1,1); glVertex3d(-1,1,-3);
glTexCoord2d(1,0); glVertex3d(-1,-1,-3);
glEnd();

glutSwapBuffers();

}


Thanks

09-09-2006, 03:34 PM
red, green, and blue values were all zero

That is black, not white.

silicon_chipper
09-09-2006, 03:46 PM
Wow, you were right. I feel so stupid. Thank you very much.