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
How do I draw a texture on top of another texture?
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement