Sign in to follow this  

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this