disabling a color in a texture

Started by
5 comments, last by Seriema 20 years, 8 months ago
Hi! I''m making a 2d game in ogl. tilebased. Got the boys running around and colliding *proud* But how do I dissable a color from being rendered? The guys running around surrounded by a blue quad! *horrible* thanx :D "No lies of sugar can sweeten the sournes of reality" }+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
Advertisement
Use glColorMask to prevent a color from being written to the frame buffer. Or you can use the texture environment and modulate the fragment color with a mask color (the constant color for example, or the primary/secondary color if you need per-vertex masking). You can also use the blending stage and modulate with a constant color. But be aware that these modulation method replaces the masked color with black, glColorMask just don''t write the other components.
You mean transparency, don''t you?

Im that case, look up alpha blending and alpha testing. Rundown: create your textures as TGA (RGBA). Enable blending or alpha test. Alpha values of 0 in the texture will not be rendered, while values 255 will be completely solid.
Ah, maybe the OP wanted color keying; disable a single color, not disable a color channel. Well, then forget about my post and follow llyod advice.
yeah, colorkeying.

I only have a .bmp loader, and no time to do any other. I could easily add a "color key" value into a file and read that (I have such a system right now, small "render shaders").

But say I have a color 100,100,50 or something that I don''t want to be visible. Do I really have to enable alpha blending for that? That glColorMask looked good until I noticed it completely disables a color (red,green or/and blue)?

"No lies of sugar can sweeten the sournes of reality"

}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
opengl doesnt have colorkeying ( except if you do it yourself in a fragmentprogram)

so the best, and easiest thing to do is to do as proposed, create an alphalayer when you load the image.
You don''t need alpha blending (unless you use it elsewhere), alpha testing will work just as well.
Basicly, you set the alpha of your normal pixels to 1 on load, and your color-key pixels to 0.
Then:
glEnable(GL_ALPHA_TEST);glAlphaFunc(GL_GREATER,0.0f); 


Now all pixels with an alpha > 0 will be drawn, other pixels will be discarded.

This topic is closed to new replies.

Advertisement