Alpha blend 3D png texture in XNA

Posted by ProgrammerAtWork on Game Development See other posts from Game Development or by ProgrammerAtWork
Published on 2012-09-12T21:07:34Z Indexed on 2012/09/12 21:51 UTC
Read the original article Hit count: 394

Filed under:
|

I'm trying to draw a partly transparent texture a plane, but the problem is that it's incorrectly displaying what is behind that texture.

Pseudo code:

vertices1 
basiceffect1
// The vertices of vertices1 are located BEHIND vertices2

vertices2
basiceffect2
// The vertices of vertices2 are located IN FRONT vertices1

GraphicsDevice.Clear(Blue);
PrimitiveBatch.Begin();

//if I draw like this:
PrimitiveBatch.Draw(vertices1, trianglestrip, basiceffect1)
PrimitiveBatch.Draw(vertices2, trianglestrip, basiceffect2)
//Everything gets draw correctly, I can see the texture of vertices2 trough
//the transparent parts of vertices1

//but if I draw like this:
PrimitiveBatch.Draw(vertices2, trianglestrip, basiceffect2)
PrimitiveBatch.Draw(vertices1, trianglestrip, basiceffect1)
//I cannot see the texture of vertices1 in behind the texture of vertices2
//Instead, the texture vertices2 gets drawn, and the transparent parts are blue
//The clear color

PrimitiveBatch.Draw(vertice
PrimitiveBatch.End();

My question is, Why does the order in which I call draw matter?

© Game Development or respective owner

Related posts about XNA

Related posts about c#