Jump to content
  • Advertisement


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


Alpha layer + Texture

This topic is 6547 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

Hi everyone, I asked about this some weeks back, and I got a method going. I am able to make a texture and query for an alpha texture, and have it all work with no hitches. But when I try to render with the texture, I get a black square. Does anyone have ''real code'' that loads a bitmap onto a texture, and then loads a second bitmap with alpha into into the texture''s alpha layer? I''m probably doing something silly wrong. Thanks! -- Goodlife ----------------------------- Those whom the gods would destroy, they first drive mad. --DirectX design team official motto

Share this post

Link to post
Share on other sites


I don´t know whether you use DirectX or OGL but this code is in OGL.
But conterting it to DirectX shouldn´t be that difficult.

void MergeTextures(char *pBase, char *pAlpha)

AUX_RGBImageRec *Texture= NULL;
char *Layer;
int i;
int iTexID;

// alpha layer

Texture = auxDIBImageLoad(pAlpha);
Layer = new char[4 * Texture->sizeX * Texture->sizeY];

// copy Texture to Layer (alpha component)
for(i=0; isizeX * Texture->sizeY; i++)
Layer[4*i+3] = Texture->data[3*i];

// base texture

Texture= auxDIBImageLoad(pBase);

for(i=0; isizeX * Texture->sizeY; i++)
Layer[4*i] = pTexture[iTexStack]->data[3*i]; // red
Layer[4*i+1] = pTexture[iTexStack]->data[3*i+1];//green
Layer[4*i+2] = pTexture[iTexStack]->data[3*i+2];//blue
// Layer[4*i+3] already contains the alpha value from above

// usual OGl texture binding stuff:

glGenTextures(1, &iTexID);
glBindTexture(GL_TEXTURE_2D, iTexID);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, Texture->sizeX,
Texture->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, Layer);

delete [] Layer;



-The alpha texture and the base texture must have the same size.
-The alpha texture must be saved in grey scale.

Hope this helps


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!