Search code examples
c#windows-8windows-store-appssharpdxdirect3d11

Loading textures with SharpDX in Windows Store App


I have converted my C# game from OpenTK (OpenGL) to SharpDX (DirectX) and have it up and running from Visual Studio 2010. I also have it up and running from Visual Studio 11 in Metro, in the Windows 8 Developer Preview. However, the Metro build is still lacking textures, so my polygons are simply colored right now. The problem is that the methods used to load images are absent in the Metro DLLs. These methods are all missing from the Texture2D class (inherited from the Resource class) in Windows Store App:

SharpDX.Direct3D11.Resource.FromStream
SharpDX.Direct3D11.Resource.FromFile
SharpDX.Direct3D11.Resource.FromMemory

Does anyone know if these will eventually be implemented in Metro? Or is there an alternate approach I could be using? Please keep in mind that I never knew a thing about DirectX or SharpDX before this, so I'm still very wet behind the ears with all this.

Finding any kind of help or information for SharpDX is not easy, which is a shame, because it seems to be a great solution for 3D in Metro using C#.


Solution

  • Good news! Alexandre Mutel, the author of SharpDX, let me know that Microsoft removed the "helper methods" from Direct3D11. It wasn't an omission by SharpDX. And he also pointed me in the right direction; to use WIC to load my textures. I found sample code here:

    http://crazylights.googlecode.com/svn/CLReach/win8/SDX_CLGC/clgc.cs

    I just needed two of the methods: LoadBitmap() and CreateTex2DFromBitmap(). I had to change the "R8G8B8A8_UNorm_SRgb" to "R8G8B8A8_UNorm", but ultimately I got it working. And now my game now looks fabulous in Metro with all it's textures in place! :)