Jump to content
  • Advertisement
Sign in to follow this  

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.



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.


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
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!