PDA

View Full Version : Transparent Texture Map question



tbalck
12-05-2000, 09:50 AM
How do you set the Alpha value for specific colors to be transparent in the texture map?

danoon
12-05-2000, 10:25 AM
I'm also curious if there is an easy way to do this. As of now I just load the bitmap textures then convert them to 32-bit changing the alpha values based on the the pixel color. Then I create the RGBA texture.

// convert 24-bit data to 32-bit
pData = new unsigned char [m_width*m_height*4];
unsigned int row,col;
for (row=0;row<m_height;row++)
{
for (col=0;col<m_width;col++)
{
int index=row*m_width*4+col*4;
int indexIn=row*m_width*3+col*3;
pData[index]=m_pRGB[indexIn];
pData[index+1]=m_pRGB[indexIn+1];
pData[index+2]=m_pRGB[indexIn+2];
pData[index+3]=255;
}
}
if (m_pRGB)
delete[] m_pRGB;
m_pRGB=pData;

// add alpha color mask
int i;
int count=m_width*m_height;
unsigned int* pData=(unsigned int*)m_pRGB;
for (i=0;i<count;i++)
{
if ((pData[i] & 0x00FFFFFF)==color)
pData[i]= (((alpha << 24) & 0xFF000000)|color);
}