Jump to content
  • Advertisement
Sign in to follow this  
KING_KONG_coder

OpenGL 24-bit bitmap partial transparency help.

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

How would I make a partial transparent bitmap in OpenGL without using alpha channels. How can I make OpenGL not draw a certain RGB color value like 255 0 255 not drawn using bitmap. Is it possible?

Share this post


Link to post
Share on other sites
Advertisement
well, if you want to write your own fragment programs then you can do that with no problems at all.

Otherwise, afaik the only way to discard a fragment that i know of based on its color is via the alpha test, ofcourse that requires that you at least constuct an alpha channel while loading the texture to have it work, so its not totally alpha channel-less, but doesnt require the source image has an alpha channel, just that one is added as its loaded.

Share this post


Link to post
Share on other sites
Quote:
Original post by vbbartlett
im not sure if it would work but I would investigate glColorMask()...


No, with glColorMask you can only tell the GL not to write red, green, blue or alpha to the frame buffer. You can only specify that per bunch of triangles but not per pixel, so you can't do color keying with that.

The alpha test is used most often for that AFAIK.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by KING_KONG_coder
How would I make a partial transparent bitmap in OpenGL without using alpha channels. How can I make OpenGL not draw a certain RGB color value like 255 0 255 not drawn using bitmap. Is it possible?
You could try something like this. I got it from CodeSampler.com in their OpenGL section.
http://www.codesampler.com/oglsrc.htm


AUX_RGBImageRec *pImage_RGB = auxDIBImageLoad( ".\\door.bmp"
unsigned char *pImage_RGBA = NULL;
if( pImage_RGB != NULL )
{
int imageSize_RGB = pImage_RGB->sizeX * pImage_RGB->sizeY * 3;
int imageSize_RGBA = pImage_RGB->sizeX * pImage_RGB->sizeY * 4;

// allocate buffer for a RGBA image
pImage_RGBA = new unsigned char[imageSize_RGBA];

//
// Loop through the original RGB image buffer and copy it over to the
// new RGBA image buffer setting each pixel that matches the key color
// transparent.
//

int i, j;

for( i = 0, j = 0; i < imageSize_RGB; i += 3, j += 4 )
{
// Does the current pixel match the selected color key?
if( pImage_RGB->data == g_keyColor[0] &&
pImage_RGB->data[i+1] == g_keyColor[1] &&
pImage_RGB->data[i+2] == g_keyColor[2] )
{
pImage_RGBA[j+3] = 0; // If so, set alpha to fully transparent.
}
else
{
pImage_RGBA[j+3] = 255; // If not, set alpha to fully opaque.
}

pImage_RGBA[j] = pImage_RGB->data;
pImage_RGBA[j+1] = pImage_RGB->data[i+1];
pImage_RGBA[j+2] = pImage_RGB->data[i+2];
}

glGenTextures( 1, &g_textureID );
glBindTexture(GL_TEXTURE_2D, g_textureID);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// Don't forget to use GL_RGBA for our new image data... we support Alpha transparency now!
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, pImage_RGB->sizeX, pImage_RGB->sizeY, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pImage_RGBA );
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!