Archived

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

jonbell

Blending

Recommended Posts

jonbell    100
Hi i am rendering some 2d images using my own format and am trying to blend out one colour. In my images all pixels with a value of 0,255,0 has its alpha set to 1 else it is 0, I am certain my data is correct. I then want to render the image with none of the 0,255,0 pixel showing. This is my code : glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); // blend out the colour mask (0,255,0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // bind texture glBindTexture(GL_TEXTURE_2D, GetTexture()); glBegin(GL_QUADS); glTexCoord2f(0,1); glVertex2f( (float) x, (float) y); // tl glTexCoord2f(0,0); glVertex2f( (float) x, (float) y + iYRes); // bl glTexCoord2f(1,0); glVertex2f( (float) x + iXRes, (float) y + iYRes); // br glTexCoord2f(1,1); glVertex2f( (float) x + iXRes, (float) y); // tr glEnd(); glDisable(GL_BLEND); When i run this with blending i just get solid black quads (i am using an orthogonal projection to render in 2d if that matters). If i turn blending off my images render fine but with the solid quads and colour key showing. This code is rendering on my HUD and i have quite a bit of other 3D stuff going on before i get here so maybe i am doing something to the state machine previously? Any ideas? Cheers

Share this post


Link to post
Share on other sites
jonbell    100
Does anyone know how to solve this blending problem? From reading up i see that if the alpha value of a pixel is 1 then the lixel should not be drawn and if it is 0 then the pixel is not blended with the current pixel in the colour buffer. I am only using 0 and 1 so i *should* be able to mask out my pixels but it doesn''t work.

Do i need to do anything to the state machine other than enable blending and 2d texturing?

Share this post


Link to post
Share on other sites
Monder    993
If you have it set so that an alpha of 0 means you can''t see the pixel and an alpha of 1 means you can then your above code will work as long as you call glColor4f(1.0f, 1.0f, 1.0f, 1.0f); Though a better idea would be to do alpha testing as OrangyTang suggested (go look up glAlphaFunc in the blue book).

Share this post


Link to post
Share on other sites