Skip to main content
gamedev.net
🔒 Locked

blending

Started by gph-gw 1 reply 550+ views
Original Post
gph-gw
gph-gw
I''m trying to texture map a cursor onto the screen, it draws fine but then the whole quad around the cursor is black. I want to blend it so that where it''s black, it shows through completely transparent, but where it''s not black completely opaque. I tried glBlendFunc(GL_ONE, GL_ONE) and that blends the black completely out but it also blends the cursor with the background slightly so it doesn''t look right. can anyone help?
Lev Povalahev
Lev Povalahev
Provide an alpha channel and use (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) as blending factors.

-Lev

Edit: spelling

[edited by - Lev Povalahev on December 30, 2003 7:59:58 AM]
GamerSg
GamerSg
Either use a format which supports an alpha channel or write a function to convert your rgb image into a rgba image with black parts having a 0 alpha channel value.

Here is some code,
r,g,b define the colour you want filtered out. *in is a pointer to your rgb image data while out is a pointer to your rgba array.


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<height;++i)
for(j=0;j<width;++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;
}
}

In your init code set the function to draw anything that has above 0 alpha value.

glAlphaFunc(GL_GREATER, 0.0f);


Once you have your texture, use this to not draw alpha values 0.

glEnable(GL_ALPHA_TEST);
//draw your stuff here
glDisable(GL_ALPHA_TEST);//remember to disable it again

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.