Graphics Reference
In-Depth Information
23. Next, we will implement the triangle renderer. Open the TriangleRenderer class
and add the following private member fields:
// The triangle vertex buffer
Buffer triangleVertices;
// The vertex buffer binding structure for the triangle
VertexBufferBinding triangleBinding;
24. We will initialize the device-dependent resources with this code. As with the axis lines
renderer, here we also need to create a vertex buffer and binding.
RemoveAndDispose(ref triangleVertices);
// Retrieve our SharpDX.Direct3D11.Device1 instance
var device = this.DeviceManager.Direct3DDevice;
// Create a triangle
triangleVertices = ToDispose(Buffer.Create(device, BindFlags.
VertexBuffer, new[] {
/* Vertex Position
Vertex Color */
new Vector4(0.0f, 0.0f, 0.5f, 1.0f),
new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Base-right
new Vector4(-0.5f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Base-left
new Vector4(-0.25f, 1f, 0.25f, 1.0f),
new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // Apex
}));
triangleBinding = new VertexBufferBinding(triangleVertices,
Utilities.SizeOf<Vector4>() * 2 , 0);
25. And finally, render our triangle with the following code that is placed in DoRender() .
This time, we use a different topology and only need to draw three vertices.
// Get the context reference
var context = this.DeviceManager.Direct3DContext;
// Render the triangle
// Tell the IA we are now using triangles
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.
PrimitiveTopology.TriangleList ;
// Pass in the triangle vertices
context.InputAssembler.SetVertexBuffers(0, triangleBinding);
// Draw the 3 vertices of our triangle
context.Draw(3, 0);
 
Search WWH ::




Custom Search