Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

agent666

Color Key Transparancy

This topic is 5303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to edit the texture data in a variable after auxDIBImageLad has been called and set the alpha components to 0 if full blue is that color. This is my code: bool LoadTransTextureFile(char *TextureFile, int TextureIDSpot) { //load a transparent Texture FILE *FileHandle = fopen(TextureFile, "r"); if(!FileHandle) return false; fclose(FileHandle); AUX_RGBImageRec *TexRec; TexRec = auxDIBImageLoad(TextureFile); if(TexRec) { for(int i=0;i<=sizeof(TexRec->data);i=i+3) { if(TexRec->data[i] == 0 && TexRec->data[i+1] == 0 && TexRec->data[i+2] == 255) TexRec->data[i+3] = 0; //set alpha attributes } glGenTextures(1, &TextureID); MD_Tex[TextureIDSpot] = TextureID; glBindTexture(GL_TEXTURE_2D, TextureID); //generate MipMaps gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TexRec->sizeX, TexRec->sizeY, GL_RGBA, GL_UNSIGNED_BYTE, TexRec->data); //set filtering options glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); // Linear Filtering } return true; } But it crashes.... [edited by - Agent666 on February 6, 2004 9:49:31 AM]

Share this post


Link to post
Share on other sites
Advertisement
The glaux AUX_RGBImageRec structure does not contain an alpha channel. You need to copy the data into a new buffer before you can set the alpha, i.e.:
GLubyte* newBuffer = new GLubyte[TexRec->sizeX * TexRec->sizeY * 4];
for (int index = 0; index < TexRec->sizeX * TexRec->sizeY; ++index)
{
std::copy(TexRec->data + (index * 3), TexRec->data + (index * 3) + 3, newBuffer + (index * 4));
if (TexRec->data[(index * 3) + 0] == 0 && TexRec->data[(index * 3) + 1] == 0 && TexRec->data[(index * 3) + 2] == 255)
{
newBuffer[(index * 4) + 3] = 0;
}
else
{
newBuffer[(index * 4) + 3] = 255;
}
}


Enigma

Share this post


Link to post
Share on other sites
That is very well, but newBuffer won''t work with gluBuild2DMipMaps without a structure defintion for newBuffer.

like this will not work:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, newBuffer->sizeX,
newBuffer->sizeY, GL_RGBA, GL_UNSIGNED_BYTE, newBuffer->data);


What is a name of a structure that holds alpha channel data and can be passed to GluBuild2DMipMaps

Share this post


Link to post
Share on other sites
You don''t need a structure. You already have the width and height of the texture, but now your data is RGBA instead of RGB, so pass it to gluBuild2DMipmaps as:
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, TexRec->sizeX, TexRec->sizeY, GL_RGBA, GL_UNSIGNED_BYTE, newBuffer); 


Also note that I changed the second parameter to GL_RGBA. ''3'' is deprecated and means ''GL_RGB'', which wouldn''t give you an alpha channel anyway.

Don''t forget to delete[] newBuffer afterwards.

Enigma

Share this post


Link to post
Share on other sites
Ok, when i show the polygons they are not transparent where the transparent colors are, do i need to enable any testing or gl_blend?

Share this post


Link to post
Share on other sites
Either:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

or:
glAlphaFunc(GL_GREATER, 0.5);
glEnable(GL_ALPHA_TEST);


Enigma

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!