I have a primative which I am rendering from a vertex buffer (positioned, colored, textured), among some meshes.

All of the meshes seem to work fine with the Z buffer, texutre transparency works fine... except for when I make my primative transparent, you can only see the cleared background, and none of the meshes behind it.

Just to give you an idea, here's some code! (obviously not all in the same method).

frontVertices = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured),
4, Device,
Usage.WriteOnly, CustomVertex.PositionColoredTextured.Format, Pool.Default);

CustomVertex.PositionColoredTextured[] vertices = frontVertices.Lock(0, LockFlags.None) as CustomVertex.PositionColoredTextured[];

vertices[0] = new CustomVertex.PositionColoredTextured(0, 0, 1, colour, 0, 0);
vertices[1] =
new CustomVertex.PositionColoredTextured(50, 0, 1, colour, 1, 0);
vertices[2] =
new CustomVertex.PositionColoredTextured(0, 50, 1, colour, 0, 1);
vertices[3] =
new CustomVertex.PositionColoredTextured(50, 50, 1, colour, 1, 1);



int alpha = 180;

Device.RenderState.TextureFactor =
Color.FromArgb(alpha, 255, 255, 255).ToArgb();
Device.TextureState[0].AlphaOperation =
Device.TextureState[0].AlphaArgument1 =
Device.TextureState[0].AlphaArgument2 =
Device.RenderState.AlphaBlendEnable =
Device.RenderState.SourceBlend =
Device.RenderState.DestinationBlend =

Device.SetTexture(0, mainTexture);
Device.SetStreamSource(0, frontVertices, 0);
Device.VertexFormat =
PrimitiveType.TriangleStrip, 0, 2);

Re: Game Technologies: Graphics Using VertexBuffer with Z-Buffer

Ralf Kornmann

If you only need full transparent and full solid you should use alpha test instead of alpha blending. If you need partial transparency you have to sort your objects back to front based on the Z value in screen space.

Re: Game Technologies: Graphics Using VertexBuffer with Z-Buffer


Hi Ralf, the entire texture needs to be transparent, as it fades out to reviel the object behind it.

Anyway, simple enough, I have solved the problem:

This was meerly a case of rendering in the right order. Because I was rendering the primatives before the meshes, I guess DirectX assumed the Z position of the primatives was behind the meshes. Unless anyone can provide a more logical explanantion