This project is read-only.

Loading textures in DX11

Mar 8, 2013 at 11:42 PM
Hello again, I'm looking into messing with textures in DX11 and it seems a lot of devs online are still using the texture APIs (D3DX11CreateShaderResourceViewFromFile) to deal with textures. Looking through Hieroglyph, I see that you're using the DirectXTK to load textures. So, I dove into the DirectXTK helper methods to see how textures are being loaded and WOW...there is a ton of code there just to load a simple texture or DDS texture. Is all that necessary? Is D3DX11CreateShaderResourceViewFromFile running similiar code that the DirectXTK helper methods are doing? Is it a best practice to use the DirectXTK for Win/Xbox game development. I know that Shawn Hargreaves recommends using it, but wanted to get your opinion :). Thanks!
Mar 9, 2013 at 3:35 PM
I chose to incorporate DirectXTK exactly for that reason - I honestly have no interest in writing a ton of file loaders that have already been written by someone else. If you are using OpenGL on other platforms, then you could probably also use a different open source alternative like libPNG or libJPG to get the file data loaded and then just copy the contents into the texture resource with your own code.

But honestly, that isn't fun code to write, and with a limited time budget, I would recommend going with another library somewhere along the way to minimize the maintenance burden from all those various pixel formats, file types, the conversions for how they are used in D3D, etc... You can do it as a learning exercise, but I would personally not want to take it on.

So to summarize a bit, the only reason I am using DirectXTK is because it was a convenient replacement for D3DX functions that I was using before that aren't supported for WinRT, and I am planning to add support for WinRT in the near future. Keep in mind that Shawn is the co-author of that library, so he is recommending his library just like I recommend Hieroglyph 3! :)
Mar 15, 2013 at 5:21 PM
That makes sense :). I didn't realize it took that much code to load a simple texture. I have been looking at libpng as a cross-platform way of loading pngs. I've found a few examples online that demonstrate loading textures with libpng in OpenGL. There's still a tad bit of code you need to write, but not nearly as much like the DirectXTK is doing. Converting the sample OpenGL code with libpng to DirectX is pretty straightforward. If I run into any gotchas, I'll be sure to ping ya back ;). Thanks!