Graphics Reference
In-Depth Information
// Initialize (create Direct3D device etc)
app.Initialize();
// Run the application
app.Run();
}
}
17. Let's first add stubs for the renderer classes so that we can test whether our project
is compiling correctly. We will add these with names according to the following files:
AxisLinesRenderer.cs
,
TriangleRenderer.cs
, and
QuadRenderer.cs
.
Go ahead and create these empty classes now and descend them from
Common.
RendererBase
as demonstrated in the
Creating a Direct3D renderer class
recipe.
18. At this point we should be able to compile and run (
F5
) the project. A blank form will
appear with the frames per second displayed in the top-left corner.
19. We will first complete the axis-lines renderer class of the renderers . Begin by
opening the
AxisLinesRenderer.cs
file and adding the following private
member fields:
// The vertex buffer for axis lines
Buffer axisLinesVertices;
// The binding structure of the axis lines vertex buffer
VertexBufferBinding axisLinesBinding;
20. Now we will add the following resource initialization code to the
CreateDeviceDependentResources
method. This consists of first ensuring
that the resources have been released via
RemoveAndDispose
and then creating
a local reference to the device.
// Ensure that if already set the device resources
// are correctly disposed of before recreating
RemoveAndDispose(ref axisLinesVertices);
// Retrieve our SharpDX.Direct3D11.Device1 instance
var device = this.DeviceManager.Direct3DDevice;
21. Next, we create our vertex buffer and binding for use in the IA stage:
// Create xyz-axis arrows
// X is Red, Y is Green, Z is Blue
// The arrows point along the + for each axis
axisLinesVertices = ToDispose(Buffer.Create(device, BindFlags.
VertexBuffer, new[]
{