Graphics Reference
In-Depth Information
Getting ready
We'll start by creating a new Windows Form Application project named
Ch02_01RenderingPrimitives
in the
D3DRendering.sln
solution:
1.
Add the
SharpDX.dll
,
SharpDX.DXGI.dll
and
SharpDX.Direct3D11.dll
references like we did in the previous recipes.
2.
Next, we will add a reference to
.\External\bin\SharpDX.D3DCompiler.dll
for dealing with our shader code.
3.
An important step before we get started is to ensure that we are copying the Direct3D
d3dcompiler_46.dll
DLL to the build directory, as this will let us compile our
shaders at runtime. To do this, open the project properties, select Build Events,
and add the following code to the Post-build event command line:
copy "$(SolutionDir)\External\Bin\Redist\D3D\x86\d3d*.dll"
"$(TargetDir)"
If you are not entirely familiar with .NET 4.5 yet, the behavior of AnyCPU
has changed. Now there is an additional option Prefer 32-bit. For all new
.NET 4.5 projects, this is selected by default—this is why we are using the
32-bit version of
d3dcompiler_46.dll
.
4.
Make sure that you have the
Common
rendering framework project (that we used in
the
Using the sample rendering framework
recipe earlier in this chapter) added to
your
D3DRendering.sln
solution, and add a reference to it to our new project.
How to do it…
For this recipe, we will first create a HLSL shader to render our primitive shapes. We will
create a
D3DApp
class that compiles our shaders and creates instances of our line, triangle,
and quad renderers.
1. The first thing we will do is create our HLSL shader file. Do this by adding a new Text
File to the project and call it
Simple.hlsl
. Add the following code to the shader file:
// Constant buffer to be updated by application per frame
cbuffer PerObject : register(b0)
{
// WorldViewProjection matrix
float4x4 WorldViewProj;
};