Jump to content
  • Advertisement
Sign in to follow this  
DarkCybo1

How do I draw a texture on top of another texture?

This topic is 2975 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

In respect to the alpha channel.

Say I have these two textures. One of a square and one of a circle.

http://i88.photobucket.com/albums/k174/Tacoliono/62673d1f.png

http://i88.photobucket.com/albums/k174/Tacoliono/f336e4ee.png

Both have alpha channels ( the white area )

I want to render the circle on top of the square, but I don't want to draw any of the circle that is alpha'd out on the square's texture. So I get this effect.

http://i88.photobucket.com/albums/k174/Tacoliono/bc7afdb7.png



It probably has to do with alpha blending, but I'm not sure how to achieve the effect

Share this post


Link to post
Share on other sites
Advertisement
Firstly, the rendering order is obviously important - square first, circle second. Put each texture on a simple quad. enable blending with glEnable(GL_BLEND), and set the blend calculation to be based on the alpha channel of the primitive being drawn with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) so that you get
fragment = alpha*circle_colour + (1-alpha)*square_color

If your circle is not going to be drawn closer according to the z-axis, you may want to disable depth testing for this draw call with glDisable(GL_DEPTH_TEST)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!