public void Render()
{
// Update the triangle vertex position/colors based on current parameters
{
var p1 = new Vector3(1.0f, 0.0f, 0.5f);
var p2 = new Vector3(-0.5f, 0.866f, 0.5f);
var p3 = new Vector3(-0.5f, -0.866f, 0.5f);
DataStream vertexStream;
context.MapSubresource(vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out vertexStream);
vertexStream.Write<Vector4>(new Vector4(p1 * Scale, 1.0f));
vertexStream.Write<Vector4>(new Vector4(P1Color, 1.0f));
vertexStream.Write<Vector4>(new Vector4(p2 * Scale, 1.0f));
vertexStream.Write<Vector4>(new Vector4(P2Color, 1.0f));
vertexStream.Write<Vector4>(new Vector4(p3 * Scale, 1.0f));
vertexStream.Write<Vector4>(new Vector4(P3Color, 1.0f));
context.UnmapSubresource(vertexBuffer, 0);
vertexStream.Dispose();
}
// Set up the pipeline state in order to render our triangle
context.Rasterizer.SetViewport(new Viewport(0, 0, window.Width, window.Height, 0.0f, 1.0f));
context.Rasterizer.State = new RasterizerState(device, new RasterizerStateDescription()
{
FillMode = Wireframe ? FillMode.Wireframe : FillMode.Solid,
CullMode = CullMode.None,
});
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 32, 0));
context.VertexShader.Set(vertexShader);
context.PixelShader.Set(pixelShader);
context.OutputMerger.SetTargets(rtv);
// Now ready to draw the triangle! (clear the background first)
context.ClearRenderTargetView(rtv, new Color(0.1f, 0.1f, 0.45f));
context.Draw(3, 0);
}