2 stupid questions

Started by
3 comments, last by devdept 16 years, 10 months ago
Hi All, 1) I know that I can draw a triangle this way: verts[0].X=150; verts[0].Y=50; verts[0].Z=0.5f; verts[0].Rhw=1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb(); verts[1].X=250; verts[1].Y=250; verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System.Drawing.Color.Brown.ToArgb(); verts[2].X=50; verts[2].Y=250; verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System.Drawing.Color.LightPink.ToArgb(); Suppose that my triangle has only one solid color, is there not a more efficient way to specify it? (one time, instead of 3 times) 2) I can draw the triangle this way: device.SetStreamSource(0, vertexBuffer, 0); device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1); How can I draw one line, than a triangle, than a point? Should I call the DrawPrimitives each time with a different Primitive type? Is there no way to make the vertexBuffer to know what entity it has to draw?!? Thanks a lot, Alberto
Advertisement
1) Not really. If you're drawing all the triangles in the batch the same colour, then you can do:
pDevice->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
and then set the colour of the triangles in the material, but that's likely to be less efficient than just specifying a colour per-vertex.

2) No, a vertex buffer is a collection of vertices, not primitives. Which is why it's called a vertex buffer and not a primitive buffer / geometry buffer [smile]
Anyway this wouldn't be any more efficient.
So I always specify color per vertex even if they are all the same.

This is true also for a Mesh with 1000 vertices and one color?


Thanks again,

Alberto
Quote:Original post by devdept
So I always specify color per vertex even if they are all the same.

This is true also for a Mesh with 1000 vertices and one color?


Thanks again,

Alberto
If the mesh doesn't have a texture, yes. Otherwise you'd probably just not bother specifying a vertex colour and use the material colour instead.
Wonderful, thanks Steve!

This topic is closed to new replies.

Advertisement