Graphics Reference
In-Depth Information
26. Lastly, we will implement our quad renderer. Open the QuadRenderer class,
and add the following private member fields:
// The quad vertex buffer
Buffer quadVertices;
// The quad index buffer
Buffer quadIndices;
// The vertex buffer binding for the quad
VertexBufferBinding quadBinding;
27. Initialize the device-dependent resources with the following code. We are initializing
our vertex buffer and binding in the same way as the axis lines and triangle renderer.
In addition, we are creating an index buffer to re-use the existing vertices.
RemoveAndDispose(ref quadVertices);
RemoveAndDispose(ref quadIndices);
// Retrieve our SharpDX.Direct3D11.Device1 instance
var device = this.DeviceManager.Direct3DDevice;
// Create a quad (two triangles)
quadVertices = ToDispose(Buffer.Create(device, BindFlags.
VertexBuffer, new[] {
/* Vertex Position
Vertex Color */
new Vector4(0.25f, 0.5f, -0.5f, 1.0f),
new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // Top-left
new Vector4(0.75f, 0.5f, -0.5f, 1.0f),
new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Top-right
new Vector4(0.75f, 0.0f, -0.5f, 1.0f),
new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Base-right
new Vector4(0.25f, 0.0f, -0.5f, 1.0f),
new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Base-left
}));
quadBinding = new VertexBufferBinding(quadVertices, Utilities.
SizeOf<Vector4>() * 2, 0);
// v0 v1
// |-----|
// | \ A |
// | B \ |
// |-----|
// v3 v2
quadIndices = ToDispose(Buffer.Create(device, BindFlags.
IndexBuffer, new ushort[] {
0, 1, 2, // A
2, 3, 0 // B
}));
 
Search WWH ::




Custom Search