Texture Mapping Problem

Started by
4 comments, last by fallout2600 21 years, 8 months ago
Is it possible in OpenGL to draw a texture on a polygon and set one color(in this case black) as a transparent color so that it doesn''t get drawn? Thanks, fallout2600
Advertisement
You can set the color of the polygon on which the texture is drawn to a color. Then the texture gets colored in that color.
I meant I don''t want a color in the texture to be drawn.
I am trying to draw sprites and get a transparent color on the sprite.
What you do is set the alpha value of the texture coordinate
to 0.0 if you want it to be transparent. 1.0 means totally
opague. Transparency is done through alpha-blending.

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

So any and all color can be transparent, not just a single one.
It''s up to you to set up and bind the texture with the
desired alpha values.
神はサイコロを振らない!
First, make sure the texture you loaded has an alpha channel. TGA files support alpha channels and are really easy to load (although, IMO, just DevIL use http://openil.sourceforge.net/ to load your images/textures). Then when you call glTexImage2D, use GL_RGBA for the component and format parameters (DevIL will take care of this for you).

When drawing, do as tangentz said and enabling alpha blending. To correct visual results, however, you''ll either have to sort your polygons and draw from back to front, or disable depth buffer writing before drawing your image via glDepthMask(false). You may have to also fiddle with the blend function.
Oh i miss-understood you. So you want black to be transparent.

You need an alpha channel in your images as the previous posters have written.

And the effect is called alpha testing (when i remeber correct).

This topic is closed to new replies.

Advertisement