Posts tagged Visual Studio

This is my first tutorial for using SharpDX. SharpDX allows you to render graphics using DirectX and C#. I recently started using SharpDX but there is not too much documentation and tutorials out there compared to other options, therefor I will be writing those tutorial as I go along.

Note: For those familiar with SharpDX you might know that it exists a toolkit to get a quick setup to get started, which gives a Game class similar to what is found in XNA. In those tutorials I will not be using the Toolkit.

In this tutorial we will not write any code, simply set up a new project in Visual Studio and add the required references.

The first step is to create a new Console Application and give it a name:

Next we need to add the references to SharpDX, for which we will use NuGet. Right click on “References” in the Solution Explorer and choose “Manage NuGet Packages…”

Search for “SharpDX”. For now we will install those named “SharpDX”, “SharpDX.Direct3D11”, “SharpDX.DXGI”, and “SharpDX.D3DCompiler”. Now if you choose “Installed Packages” it should look like this:
As you can see, there are many SharpDX packages available on NuGet, those we added are required to render a simple scene and compile our shaders.

We now have a correct project set up, in the next tutorial we will look at creating a simple window.

In December 2015, SharpDX 3.0.0 was released, followed by 3.0.1 in January 2016. This new version features several major changes, as well as some new features. For example, the assemblies are now more light weight by for example moving mathematics to a separate assembly. SharpDX now also supports Direct3D12 (requires Windows 10).

What’s removed and when shouldn't I upgrade?

But while Direct3D12 is now present, Direct3D10 has been removed, along with the toolkit. SharpDX 3.0.0 also requires .NET 4.5, so if you can’t use that, you will have to stay on 2.6.3. Some pretty nice helper functions, such as Texture.FromFile(...), which allowed easy loading of textures from files are also no longer supported (I will cover how to load textures in a later tutorial).

So, as we are geeks who always wants the latest and greatest we will from now on use SharpDX 3.0.1. Below are the steps on how to upgrade the Part 4 tutorial project to SharpDX 3.0.1:

Enter the following command:Update-Package SharpDX.Direct3D11 -Version 3.0.1
You should get an ouput similar to this:
This will also update SharpDX and SharpDX.DXGI to 3.0.1, because SharpDX.Direct3D11 depends on those.

Now we also have to update SharpDX.D3DCompiler, using the following command:Update-Package SharpDX.D3DCompiler -Version 3.0.1

We will now be at version 3.0.1, but if you try to build you will get several compiler errors:
This is because all math has moved into a separate assembly, SharpDX.Mathematics, and RenderForm has moved into the SharpDX.Desktop assembly, so we have to install those as well. So run the following two commands in the NuGet console:Install-Package SharpDX.Mathematics -Version 3.0.1
Install-Package SharpDX.Desktop -Version 3.0.1

Build the project again, it should now compile and run correctly, but now with SharpDX 3.0.1.

NuGet says there are no updates are available?

This happened for me as well first, if NuGet gives the error message:

No updates available for ‘SharpDX.Direct3D11’ in project ‘MySharpDXGame’.

Then you will probably have to clear the NuGet cache. Use the following steps:

Go to “Tools” -> “Options…”

Open “NuGet Package Manager” tab

Click “Clear Package Cache”

Re-run the commands in the console, it should now update correctly.

This concludes tutorial 4.5. All the tutorial sources on GitHub have now already been updated to SharpDX 3.0.1, so if you download the code there you won’t have to do those steps yourself.