[SOLVED] D3DX11CreateShaderResourceViewFromFile - deprecated.

Started by
4 comments, last by Buckeye 9 years, 11 months ago

Hello,

I am learning Direct3D and I am following this lesson.

When I was supposed to to load a texture using:


HRESULT D3DX11CreateShaderResourceViewFromFile(
  _In_   ID3D11Device *pDevice,
  _In_   LPCTSTR pSrcFile,
  _In_   D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
  _In_   ID3DX11ThreadPump *pPump,
  _Out_  ID3D11ShaderResourceView **ppShaderResourceView,
  _Out_  HRESULT *pHResult
);

I came across microsoft reference , stating:

Note The D3DX (D3DX 9, D3DX 10, and D3DX 11) utility library is deprecated for Windows 8 and is not supported for Windows Store apps.
Note Instead of using this function, we recommend that you use these:

  • DirectXTK library (runtime), CreateXXXTextureFromFile (where XXX is DDS or WIC)
  • DirectXTex library (tools), LoadFromXXXFile (where XXX is WIC, DDS, or TGA; WIC doesn't support DDS and TGA; D3DX 9 supported TGA as a common art source format for games) then CreateShaderResourceView


So I went ahead and downloaded "DirectXTex.zip" from DirectXTex .

I unzip it, place it in some random directory... and end up looking at "DirectXTex\DDSTextureLoader" containing the ".h" and ".cpp" files.
I link those files to my project (after painful failures and simply pointing to additional includes to ".h" and linking ".cpp" by dragging to project instead of failing documentation) and use


// Load texture.
CreateDDSTextureFromFile(dev, L"poop.jpg", 0, &cubesTexture); 

(Without knowing what "DDS" actually means, skipping the overly-complicated text on the internet) ... wham.. bham... and it compiles.



I launch it... and... 33etz4k.jpg


Any idea on how to whack this sucker? I'm currently stuck and unable to continue, so any help would be much appreciated.

-----
I have tried compiling it into a library using visual studio project files from "DirectXTex\DirectXTex" and linking via "additional library paths" (or similar name) and putting a dependency of generated ".lib" in the linker. This failed to even compile with an unresolved external symbol (needles to say the linker didn't like it).

Advertisement

DDS (DirectDraw Surface) is a texture format.

If you want to load a .jpg texture, use the WICTextureLoader (since it supports BMP, JPEG, PNG, TIFF, GIF, etc).

Anyway, I think that error is being caused by something else. Which Visual Studio version are you using? And did you use the appropriate project file to compile DirectXTex?

Did you call CoInitialize or CoInitializeEx?

The library assumes that the client code will have already called CoInitialize or CoInitializeEx as needed by the application before calling any DirectXTex routines

EDIT:



I have tried compiling it into a library using visual studio project files from "DirectXTex\DirectXTex" and linking via "additional library paths" (or similar name) and putting a dependency of generated ".lib" in the linker. This failed to even compile with an unresolved external symbol (needles to say the linker didn't like it).

I'm pretty sure you have to compile it to a library in order to use it.

Can you write a copy of the errors here?

I've only used DIrectXTK (not DirectXTex) but I didn't have any problem linking.

thankyouyellow.gif TiagoCosta ! You saved my day (literally, by saving my mood).

I managed to solve it by using WIC-based function (without compiling the library, direct implementation linkage).

DDS (DirectDraw Surface) is a texture format.

If you want to load a .jpg texture, use the WICTextureLoader (since it supports BMP, JPEG, PNG, TIFF, GIF, etc).


I am a 100% beginner, so could I ask you such silly questions:

* Is using "WIC" is the main format for those listed file/image formats and the standard way of doing things?

* Am I actually using an official and main method to load images using Direct3D11 ?


Did you call CoInitialize or CoInitializeEx?

The library assumes that the client code will have already called CoInitialize or CoInitializeEx as needed by the application before calling any DirectXTex routines


No, I did after you mentioned that and I spotted it on that website after as well. It worked, but being myself, I removed it and tried, it still works. So as long as it works, I'd rather not call those methods even though they are mentioned (I'm assuming they are needed in some other specific calls).


* Is using "WIC" is the main format for those listed file/image formats and the standard way of doing things?
* Am I actually using an official and main method to load images using Direct3D11 ?

Windows Imaging Component or WIC is a standard way of loading images of various codecs on Windows (since Vista I think). Loading textures (to be used as image data) using the WIC is a common approach in Direct3D.

With DDS textures you can store data in the same format that is used within a D3D texture object. It is important to remember that a texture doesn't necessarily contain image data (i.e. you might use a texture to store a height map or a whole range of other things), the DDS format allows you to store this data in the various texture formats. You can also use the D3D texture block compression (BC) formats within a DDS.

The DirectXTK project is maintained by Microsoft. Chuck Walbourn has been involved in DirectX since the early days on Windows 95. These methods for loading your texture data are great to use. The actual format you choose to use really depends on your storage constraints, and your asset workflow.

Justin Stenning | Blog | Book - Direct3D Rendering Cookbook (using C# and SharpDX)

Projects: Direct3D Hook, EasyHook, Shared Memory (IPC), SharpDisasm (x86/64 disassembler in C#)

@spazzarama

 

Thanks spazzarma, that cleared my questions smile.png

Regarding the DirectXTK and DDS files - a bit of testing indicates the CreateWICTextureFromFile does not include DDS files (and the docs for WICTextureLoader don't mention it.) For DDS files, use CreateDDSTextureFromFile which is part of the DDSTextureLoader interface.

If you have a generic loader with a variable filename, test the file extension, and use CreateWIC.. if not DDS, else use CreateDDS.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement