Jump to content
  • Advertisement
Sign in to follow this  
DarkCybo1

How to draw a texture on another texture?

This topic is 2910 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
Advertisement
Put your blood texture on its own Quad, then make sure you draw it last or use Zdepth to keep it in front. Is this what you mean?

Share this post


Link to post
Share on other sites
I already know that part, the tricky part is making sure the parts of the blood texture that AREN'T on the enemy sprite or on the ground tile aren't drawn, know what I mean?

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
Would it be smart to render my blood texture directly to the texture of the zombie (with FBOs or something), instead of re-rendering the blood each frame?

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!