Archived

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

Jumpman

black = Transparent in sprite blitting

Recommended Posts

another dumb question.. (due to my crash course on openGL :D) I am trying to render a sprite where BLACK is transparent but I don''t really want to use masks. Ive tried various Blend and Alpha functions/Combinations but can''t seem to get it to work.. I don''t really want to blend it as I don''t want it blending (or merging in) with any graphics underniegth. can this be done without using masks ?? I understand that I can never use black in my graphics cheers and thanks for your help

Share this post


Link to post
Share on other sites
Well you need to use the following
after enabling GL_BLEND

glBlendFunc(GL_SRC_ALPHA,GL_ONE);

This should make all black in textures transparent.

I myself tried alot of combinations before finding this somewhere. Hope it helps

Share this post


Link to post
Share on other sites
I''m looking for this too, I''ve tried the above suggestion and others but nothing seems to do the trick like a mask does. I''d appreciate any advise on the topic. (BTW, could it work to use a different color for alpha like maybe a shade of grey? 0.5 or something? I don''t know..)

Share this post


Link to post
Share on other sites
Yeah, there''s no good way to fake color keying with blending modes. Just make the durn alpha layer.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m pretty sure glAlphaFunc will work. I''ve done it a long time ago. So this a little fuzzy right now.

Share this post


Link to post
Share on other sites
It is possible.

I dont know exact source code, but I''ve seen it on the forum, so use search

What u nead to do is enable the blending buffer on the texture and manualy, go through every pixel and modify its transperancy to 1 if color is black (0,0,0) or 0 if its any other color (this all can be done in the loading stage of course)


______________________________
My Website:
or directly at http://home.attbi.com/~antonweb/
"I''ve read about...doom being used to manage unix programs(you "kill" the processes)" dede

Share this post


Link to post
Share on other sites
actually the alpha function did work (didn't on the first compile but has been fine since (go figure ;-). no blending, just black = transparent.. now got a demo where I have some sprites floating around and some scrolling text (memorys of my old amiga/64 days come flooding back).

got some code to go though the pixels and set the alpha for not 0,0,0 (well any colour really)


/**
* Copy the RGB image in to the RGBA image out, giving all pixels of color
* (r,g,b) an alpha of zero and the other ones an alpha of 255.
*/
void ColorKey(GLubyte *in,GLubyte *out,GLubyte r,GLubyte g, GLubyte b, unsigned int width,unsigned int height)
{
unsigned int i,j;
for(i=0;i {
for(j=0;j {
out[4*(i*width+j)+0]=in[3*(i*width+j)+0];
out[4*(i*width+j)+1]=in[3*(i*width+j)+1];
out[4*(i*width+j)+2]=in[3*(i*width+j)+2];
if(r==in[3*(i*width+j)+0] &&
g==in[3*(i*width+j)+1] &&
b==in[3*(i*width+j)+2])
out[4*(i*width+j)+3]=0;
else
out[4*(i*width+j)+3]=255;
}
}
}


check http://www.cs.umu.se/~dva97tha/tutorials/glblending.html and look for Alpha Test

hope that helps somebody (and me :D)

just go to work out how to splice it into the picture loading code.

[edited by - jumpman on May 2, 2003 10:44:46 PM]

Share this post


Link to post
Share on other sites
scratch all of that.. :D

Looking at the latest IPicture code (which I am also using), it sets the alpha of all black pixels (could be modified to match any color).

I''m in the process of changing the Ipicture code at the moment so it can load images from disk (which it already does), streams (IStream *), resource files and from a memory buffer (more specific commands). can also add in a function to set the alpha conversion check so bright pink could also be used (or any colour).. just trying to make nehe great code into a more generic (and specific) library to handle loading and manipulating textures.

Share this post


Link to post
Share on other sites