Graphics Reference
In-Depth Information
1, 4, 5, // Top B
5, 4, 7, // Back A
5, 7, 6, // Back B
4, 0, 3, // Left A
4, 3, 7, // Left B
3, 2, 6, // Bottom A
3, 6, 7, // Bottom B
}));
8.
Finally, we implement DoRender in exactly the same way as for the QuadRenderer
class, except here we're using 36 for the DrawIndexed method call to draw our
vertices and use the vertexBinding and indexBuffer member fields.
9.
Back in D3DApp.cs , we can now create and initialize our CubeRenderer instance
and call it's Render method within the render loop (the same location where the
quad is created and then rendered).
// Create and initialize cube
var cube = ToDispose(new CubeRenderer());
cube.Initialize(this);
...
// Render cube
cube.Render();
Now let's create our sphere renderer.
10. First, copy the GeometricPrimitives.cs source file from the downloaded code
to your project—be sure to change the namespace as appropriate. This contains the
GeometricPrimitives static class with a GenerateSphere method that will
generate the vertices and indices for our sphere with the provided radius. This is
based on a port of the DirectX Tool Kit C++ code.
11. Create a new renderer class: SphereRenderer.cs . Add the appropriate SharpDX
using directives and descend from the Common.RendererBase abstract class.
12. Override the CreateDeviceDependentResources method and create the
vertex and index buffer using the following code. Create the private member fields
as appropriate and also remember to call RemoveAndDispose to release the
buffers first.
Vertex[] vertices;
int[] indices;
// Generate vertices and indices
GeometricPrimitives.GenerateSphere (out vertices, out indices,
Color.Gray);
// Create vertex buffer
 
Search WWH ::




Custom Search