How to draw a texture on another texture?

Started by
7 comments, last by Erik Rufelt 13 years, 4 months ago
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
Hey babe.
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?

Cheers

Lee

Code is Life
C/C++, ObjC Programmer, 3D Artist, Media Production

Website : www.leestripp.com
Skype : lee.stripp@bigpond.com
Gmail : leestripp@gmail.com

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?
Hey babe.
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.
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.
Check your Blend function. You must have it set wrong if its not mixing right.

Cheers

Lee

Code is Life
C/C++, ObjC Programmer, 3D Artist, Media Production

Website : www.leestripp.com
Skype : lee.stripp@bigpond.com
Gmail : leestripp@gmail.com

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?
Hey babe.
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]
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 alphaglBindTexture(GL_TEXTURE_2D, zombieTexture);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);drawZombie();// Drawn invisible only to alpha cause of color maskglBindTexture(GL_TEXTURE_2D, bloodTexture);glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);drawBlood();// Drawn invisible only to alpha cause of color maskglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);drawBlood();// Drawn visible masked inside the zombie

This topic is closed to new replies.

Advertisement