How to "install" Directx (or other graphic SDK) in C#? - c#

Is there any possibility to write Directx applications using C# ? How to install directx sdk for C# ? And what is the best (or most used) graphic library (framework) for C# ?

You will find an installer included with the DirectX SDK, stored in the redist folder after you install the SDK on your machine. The SDK download is here. You only need it when you write native code or target .NET version 2 or earlier. .NET 3 and up already has a dependency on DirectX so its installer already covers your needs.
By far the most popular graphics libraries in .NET programming are System.Drawing and System.Windows.Media. They are wrappers for, respectively, GDI+ and a DirectX wrapper named Milcore. GDI+ uses software rendering and is thus highly compatible but not particularly fast. Milcore is used by WPF, it doesn't expose all of the DirectX capabilities, just the ones that a WPF program needs.
For game programming, the XNA framework is a common choice. Biggest reason to use it is its capability of running on multiple platforms, Windows, XBox and Phone, wrapping their respective low-level graphics libraries. DirectX on Windows has plenty of 3rd party wrappers for it, SlimDX is popular. There used to be one from Microsoft named "DirectX For Managed Code" that had wrappers in the Microsoft.DirectX namespace but they deprecated it. The last SDK that included it was February 2010. Not recommended, XNA replaced it.

You should use SharpDx...
http://code.google.com/p/sharpdx/

I recently asked a question about SlimDX, which is a .NET Wrapper around DirectX. It's pretty up to date and more flexible than XNA (for instance, for scientific visualization apps). There are some tutorials although i'm told as its so similar to DirectX all you need to know is how to setup a device and then just use the DirectX equivalents from there.

Related

Cross-platform OpenGL rendering in Xamarin

We're developing very similar applications for Windows and Android using Xamarin platform and C#. Both will incorporate some on-screen and off-screen 3D rendering, such as 3D mesh visualization.
We'd like to implement this as cross-platform as possible. How is this usually done in Xamarin? Is it better to do rendering in C++ code, or is there a C# wrapper with abstractions over platform-specific context creation etc.?
After some time I can answer my own question.
At least in my case it turned out to be more convenient to use OpenGL from C++. We just built a shared library from C++ code and link it to .NET dll's using DllImport.
Our tool for building C++ libraries is CMake, however you can use other build systems, such as new features of VS2015.
One particular benefit of this solution is that you can reuse this code anywhere else: in iOS application, desktop application for Windows, Mac, Linux, etc.

Does DirectX 11 support .NET?

Can I use DirectX 11 from C# app?
Need to use DirectSound from WPF application. .NET 4 W7 x64
You may also want to consider the newer SharpDX. The biggest differences from SlimDX are that it doesn't support DX9 (though that's irrelevant here), and the API is directly generated from the DX SDK headers. You could even begin making Metro style apps in Windows 8 because it's ready to support Direct3D 11.1.
From Chuck Walbourn's Blog Titled: Games for Windows and the DirectX SDK.
He seems to be recommending the SlimDx Library, according to their documentation it does support DirectSound
From the above blog:
The modern version of the DirectX SDK is designed for C/C++ native
developers. If you are looking for .NET solutions for using DirectX
technology, there are many options available although the choice of
solution depends on your specific needs:
....
•For a developer using the Windows Presentation Foundation but wants
to use the new DirectX 11 APIs, the Windows API Code Pack provides
managed assemblies for Direct3D 10.1, Direct3D 11, Direct2D,
DirectWrite, DXGI, and the Windows Imaging Library (WIC) along with
many other Windows 7 features. The latest version supports .NET 4.0,
and x64 native “anycpu” applications. Note you still need to install
the DirectX SDK to get the HLSL compiler (FXC.EXE) tool.
•For
developers who are invested in Managed DirectX 1.1 but are looking for
updates to address the limitations I note above, the open source
SlimDX library is designed to mimic Managed DirectX 1.1 for just this
purpose. It includes support for x64 native “anycpu” applications,
includes modern DirectX support, and is compatible with the .NET 4.0
runtime.
....
If you want to use DirectX 11 with C# you need a wrapper
Look at the following link
http://slimdx.org/
Unfortunately, both SlimDX as well as SharpDX are no longer being developed. They both still work, even with .NET6.0 (as far as I can tell), but no new features or bug fixes will make it into these.
The .NET Foundation has a new project Silk.NET that apparently targets to become a replacement for the former two and is still being developed. When I have to update my projects that currently use SlimDX I'll take a look at it.
Bop, if you are just plan on just playing sounds then FMOD is another alternative, there is a C# wrapper available for this. If you plan on more than this, then I would like above recommend Sharpdx as it is still being supported.
Here is one way I have found. First you need to install DXSDK (I have June 2010 and SDK for Windows 7). Go to "Add reference" dialog press "Browse" , go to "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" or "C:\Windows\Microsoft.NET\Managed DirectX\v9.02.2904" then choose proper dll. For example - Microsoft.DirectX.dll. Then add "using Microsoft.DirectX" directive to your project.

Is it possible to use WPF on unix?

I heard about Mono project but only in regards to winforms. Will it work with WPF?
WPF under Mono does not exist.
At this point, no group in the Mono project has plans to implement Windows Presentation Foundation APIs as part of the project.
The mono team propose using Silverlight/Moonlight instead:
Silverlight implement a subset of the WPF APIs and is available on Windows, MacOS X and through our own open source effort Moonlight it is available on Linux and other Unix systems.
There is a library called Silverform SDK that aims to provide cross-platform WPF and Silverlight implementation.
The library is implemented in managed code and currently works with OpenTK and Unity3D as render backends. Major functionality, such as binding, layout, main controls and primitives, has already been implemented (check Unity web player demos here). Initially it has been focused on Unity3d render, while support for standalone Mono applications will be added as a separate build in the future.
Disclaimer: I am one of the developers of the library.

When do I need the Windows SDK and what is .NET for?

I am a student and after taking some introductory programming courses in Java, C, and just finishing up a book on C++, I would like to start developing applications for Windows.
I have done my best to page through google and find the answers I need, but I seem to be at a loss.
When would I need the Windows SDK over just the regular API?
And what is .NET and why would I need it?
What is so special about C# and should I use that over C/C++?
When would I need the Windows SDK over just the regular API?
The SDK includes headers, libraries, tools, etc., that give you access to the API (and to .NET, for that matter). For example, a typical API-based program will start with #include <windows.h> -- but without the SDK, you don't have a copy of Windows.h to include. Likewise, the SDK includes the compilers (the same actual compilers included in the current version of Visual C++), linkers, debuggers, etc., necessary to actually build an API-based program.
And what is .NET and why would I need it?
.NET is a couple of things: a virtual machine that executes code in what Microsoft calls "intermediate language" (IL). It's also a (large) library of code in IL for everything from window management and drawing to communications, system management, etc.
You'd need it primarily if you were writing code in a .NET-based language such as C#, VB.NET, etc.
What is so special about C# and should I use that over C/C++?
C# is (by far) the preferred language for .NET development. Microsoft did develop .NET versions of Visual BASIC, and something at least quite similar to C++, but both tend to lag behind C# (at best).
So, if you're developing code specifically for Windows (especially if it includes a GUI), C# is probably your first choice. Microsoft does a lot more to support it than to support C or C++. That shows up in better support in both libraries and tooling.
The primary argument in favor of using C or C++ would probably be that you're developing primarily for Linux, and then porting the code to Windows. You can still do such development in C# if you want to (e.g., you can run C# and .NET under Linux using Mono), but especially if you're doing the development work under Linux, you lose most of the advantages.
On the other hand, if your code doesn't involve a GUI anyway, you might be able to write portable C or C++, and just compile it under both Windows and Linux. In such a case, using C# could involve extra work, such as having to install Mono to run the code under Linux--not a terribly difficult task, but even a fairly easy installation can be more work than no installation at all.
Windows SDK is a low-level framework for developing applications specifically for Windows. You could use it for your development. However, the APIs are low-level and a little difficult to use and maintain.
Alternatively, you could use .Net. .Net is a framework that includes runtime support for your application. It has many packages, I am sure you will find something useful in .Net. .Net needs a runtime for executation and is not compiled natively to the platform. However, it is easier for software development mostly because the APIs are higher level.
C# is the recommended language for Windows specific programming, specially on .Net. Not that it is the only language, you could also use C/C++, but they are not supported by Microsoft actively. For example, if you use C#, creating a GUI application could just a few mouse clicks. Using C++, you would need to manage your windows instances.
Typically, you would only use C/C++ for Windows programming if you are doing cross-platform programming or some low-level stuffs.

Is it possible to create a Mono bundle that includes WPF libraries?

I know WPF libraries aren´t implemented by mono class library, however(as far as I know) the mono 2.6 runtime is fully compatible with the .NET 2.0/3.5 runtime, so if the WPF libraries only make PInvoke calls to windows api it is theoretically possible to run a wpf application on windows using the mono runtime.
The reason for wanting that is deploying a wpf application as a standalone executable for windows. Has anyone tried something like that before? If so, what were the results?
In short... No
At this point, the Mono project does not have plans to implement Windows Presentation Foundation APIs as part of the project
Mono will provide Moonlight support which, from what I understand, would also use a subset of XAML to create its UI (the same as Silverlight does) but there are legal complications involved. Such as, it's limited to non-microsoft and non-mac platforms.
If you want to find a list of open-source cross-platform alternatives to WPF/XAML I'm working to compile a list of viable alternatives.
Well I did give it a try with little success. I first checked with corflags if required dll-s are implemented in mixed mode (PresentationFramework, PresenationCore, WindowsBase, System.Xaml). They are all pure CIL implementations so that should work fine with mono. Next I installed mentioned DLLs into mono's GAC and tried running a very simple WPF application. This is what I got:
Assertion at mini-codegen.c:1186, condition `reginfo [sreg].born_in
0' not met
This application has requested the Runtime to terminate it in an
unusual way. Please contact the application's support team for more
information.
So although in theory this should all work, WPF is probably way to complex to run out of the box on mono, it would be cool if there was a pure CIL implementation of WPF that was compatabile with both mono and .NET Framework.
As much as I know, Mono does not support WPF.
Also, WPF uses graphics modules and interacts directly with the GPU. So I can't see how u can use WPF with no hidden pinvokes.
Sounds like you need to read about WPF architecture to better understand it.
http://msdn.microsoft.com/en-us/library/ms750441.aspx
Many pieces are missing in Mono and solely available in .NET. Therefore, your "theory" is not correct, and you cannot run WPF applications on Mono, even on Windows.
At MIX 2010 Miguel de Icaza said in his session that Mono isn't going to support WPF. Anything tangentially related to WPF-like support is only to provide what is needed for Moonlight.
Not fully, but..
You can use Moonlight 4 ( silverlight 4 ) in a desktop mode:-
https://github.com/inorton/MoonBase - MVVM helpers
https://github.com/inorton/XamlPreviewer - XamlPad clone

Categories