Texture as a background and other vertex drawing: problem.

NeoAsimov

Newcomer
Joined
Jan 20, 2004
Messages
4
Hello,


I have a little problem in DirectX 9 (using CSharp). I need to put a background(texture) to my scene. Everything work fine, my bitmap appear without problems. Im using a Quad to draw my texture on.


The problem appear when I try to draw other primitive (triangle) in front of my Quad (background).


There is some code:


// The quad buffer.
vertexTexture = new VertexBuffer( typeof(CustomVertex.TransformedColoredTextured), 4, device, Usage.WriteOnly, CustomVertex.TransformedColoredTextured.Format, Pool.Default);

// Note: Im assigning my vertices correctly, I'll not post the code here.



device.BeginScene();

// There im trying to write some colored triangle.
for (int i = 0; i < LVRTSDisplay.SectorNumber;i++)
{
device.SetStreamSource( 0, vertexBuffer1, 0);
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, (2 * LVRTSDisplay.ArcNumber));
}

device.SetStreamSource( 0, vertexTexture, 0);
device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
device.SetTexture(0, textureBackground);
device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

device.EndScene();
device.Present();



The first time that I render this, I can see my first drawed triangles and after I can see my background. But the second time I render it, it's like if my triangles are now drawed. It seem to be the result of:

device.SetTexture(0, textureBackground);
device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

If I switch my code and draw my background first, I'll never see my triangles.

I really dont know what,s the problem there.

Thank for your help/hints about this problem.


Salutations,
 
I'm no expert, not by a long shot:( But the line in your render code;

device.SetStreamSource( 0, vertexBuffer1, 0);

Why are you using an array subscript and not simply;

device.SetStreamSource( 0, vertexBuffer1, 0);
 
Hello!


Becose I have an array of VertexMatric(this array is in reallity the green spots on the image.)



Salutations,
 
just a thought, have you got the ZBuffer enabled?

device.RenderState.ZBufferEnable = true;

the zbuffer contains the flip screens pixels with a depth number ( z ) assigned to every pixel so as to draw layer apon layer while taking care of the problem of drawing with depth.
 
Back
Top