Michael Springer

I am trying to draw a masking square in front of my application's display. The display uses VertexPositionTexture format vertexes. I was hoping to draw the square using a VertexPositionColor vertex, but it looks like Vertex types cannot be mixed on a single device.

While I can create a single-color texture in code and throw it on the square, it looks pretty bad when it expands. A very noticable ring appears around the edges. Without a texture, it will not draw while TextureEnabled is set to true.

Is there a means to draw a primitive without a texture when using VertexPositionTexture



Re: Game Technologies: DirectX 101 Drawing a primitive without a texture

Pieter Germishuys

Whenever you want to render a primitive with another type of Vertex Format/Declaration you will need to set the vertex format again.
The pattern you can follow is

1) Set your Buffers (Index/Vertex)
Device.SetStreamSource(...);
Device.Indices= ...;
2) Set Vertex Format/Declaration
3) Render your primitives
Device.DrawPrimitives(...);
Device.DrawIndexedPrimitives(...);

That's pretty much it.
This means that you can have a user defined object such as RenderableEntity that contains it's own Vertex Format/Declaration and own materials etc.. and then just pass it to your renderer which will check and set it's Vertex Format/Declaration and other properties for rendering.

I hope this helps.
Take care.





Re: Game Technologies: DirectX 101 Drawing a primitive without a texture

Michael Springer

I tried setting it up as you suggested, but I appear to be missing something as I keep getting a "method call is invalid" runtime error on the second DrawIndexedPrimitive call. I currently have my rendering code set as such:

effect.CommitChanges();
effect.Begin();
foreach(EffectPass pass in effect.CurrentTechnique.Passes) {

pass.Begin();
device.VertexDeclaration = vertDeclTex;
device.Vertices[0].SetSource(vertBuffTex, 0,
VertexPositionTexture.SizeInBytes);
device.Indices = indBuffTex;
device.DrawIndexedPrimitives(
PrimitiveType.TriangleList, 0, 0, vertTex.Length, 0, 2);

device.VertexDeclaration = vertDeclPrim;
device.Vertices[0].SetSource(vertBuffPrim, 0,
VertexPositionColor.SizeInBytes);
device.Indices = indBuffPrim;
device.DrawIndexedPrimitives(
PrimitiveType.TriangleList, 0, 0, vertPrim.Length, 0, 2);
pass.End();

}
effect.End();

I have also tried setting it up as two completely separate effect Begin-End cycles, but I get the same error and expect that is invalid anyway.