Sign in to follow this  

How to draw a texture on another texture?

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

Basically, I'm making a completely 2D platformer.

I want to achieve a blood decal effect, meaning, I have a blood texture that I want to appear on the tiles and even on enemy sprites. But when I draw the blood texture, I want it to use the alpha channel of whatever it is being drawn on.

This is what I mean:

http://i88.photobucket.com/albums/k174/Tacoliono/16b95fd8.png

Share this post


Link to post
Share on other sites
If you can multiply the blood texture alpha with the zombies texture alpha. the blood left out should end up being a 1*0=0 situation which should give you what your looking for.

Share this post


Link to post
Share on other sites
Are you using shaders?
The easiest way is to multiply the alpha of both textures for the alpha blending.

Without shaders you could do it with a multi-texturing extension, though I don't remember exactly how those work.

Share this post


Link to post
Share on other sites
Only if you have a separate texture for each zombie, or just one zombie, and are willing to reset the texture whenever a zombie should be drawn without blood again.

Your best and easiest option is multi-texturing. See the following page for some examples: http://www.opengl.org/wiki/Texture_Combiners.

An alternative is the stencil buffer, though results may not be perfect if you rely on alpha blending for edge antialiasing. It could yield good results though.

A second alternative which may or may not look acceptable is to create your back-buffer with an alpha channel. Then when you're ready to draw your zombie with blood, clear just the alpha to zero, draw the zombie, then use glBlendFunc(GL_DST_ALPHA, GL_ONE) to draw the blood. Actually that won't work at all, but you could use texture combiners together with destination alpha.

[Edited by - Erik Rufelt on December 25, 2010 8:11:57 PM]

Share this post


Link to post
Share on other sites
If you're still working on it, there's an easier (though less efficient, but probably not enough to matter) way if you have a back-buffer with an alpha channel.

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT);// Clear only alpha

glBindTexture(GL_TEXTURE_2D, zombieTexture);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawZombie();// Drawn invisible only to alpha cause of color mask

glBindTexture(GL_TEXTURE_2D, bloodTexture);
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
drawBlood();// Drawn invisible only to alpha cause of color mask

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
drawBlood();// Drawn visible masked inside the zombie

Share this post


Link to post
Share on other sites

This topic is 2545 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.

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