• Advertisement

Archived

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

Texture Mapping Problem

This topic is 5727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

  • Advertisement