Load texture in directX 11.1

13,652

Solution 1

Take a look at DDSTextureLoader in DirectxTK.

edit He explicitly asks how to load a DDS texture. Please read the question carefully before down-voting.

Solution 2

There's always been a distinction between "Direct3D" and "D3DX", but it's not necessarily obvious to everyone. All versions of D3DX are now deprecated, are not in the Windows 8.x SDK, and can't be used by Windows Store apps, Windows phone 8.x apps, or Xbox One apps. Read Where is the DirectX SDK? for more information.

The main replacement libraries for D3DX are DirectXTK, DirectXTex, and DirectXMesh. These support all Direct3D 11.x platforms including Windows Store apps for Windows 8.0, Windows Store apps for Windows 8.1, Windows phone 8.x, Xbox One, and Win32 desktop apps for Windows Vista, Windows 7, and Windows 8.x.

Like lots of D3DX functions, D3DX11CreateShaderResourceViewFromFile is a everything-and-the-kitchen-sink tool which means it is hard to know when it is going to be a very fast function or an extremely slow function.

There are two different options for replacing this function: DDSTextureLoader and WICTextureLoader. These are part of the DirectXTK and there are 'standalone' versions in the DirectXTex package as well.

  • DDSTextureLoader is a very light-weight loader for DDS files. It's very efficient, but performs no run-time conversions or resizing--which means if it's really an old Direct3D 9 DDS files with 24-bpp format data for example, it can't be loaded and must be converted to a modern format. It can deal with feature level limitations for mipmapped DDS files by 'stripping' higher-level mipchains. This is ideal for loading pre-built textures that are fully 'cooked'. DirectXTex is a library for doing the 'cooking', but the Visual Studio 2012/2013 content pipeline can also generate DDS files.
  • WICTextureLoader is a "less heavy-weight" loader for standard image files using WIC which has built-in support for BMP, JPG, PNG, TIF, and GIF. It can only load 2D textures, and can try to use the GPU's automatic generation of mipmaps if supported for the given format. It can do image resizing at runtime for feature level limitations. Ideally you'd use DDS files created at build time, but WICTextureLoader is useful in cases where you can't pre-convert an image file to a DDS.

See this blog post for more detail.

See the Living without D3DX blog post for a full table of recommended replacements for D3DX11.

Note if you are using Direct3D 10 and D3DX10, the recommendation is to move to Direct3D 11.

Share:
13,652
user3877301
Author by

user3877301

Updated on June 22, 2022

Comments

  • user3877301
    user3877301 almost 2 years

    I'm reading http://www.braynzarsoft.net/ tutorials for DX11 but I mainly learning programming on DX11.1 with metro style app. as I continue to learn I find out some features in Dx11 are not anymore in DX11.1,like D3DX11CreateShaderResourceViewFromFile that tutorial used to load a texture but in DX11.1 we doesn't have this! my question is how can I load a DDS texture in DX11.1 ? I want to replace that function in this Code so that I can load a DDS texture:

    hr = D3DX11CreateShaderResourceViewFromFile( d3d11Device, L"braynzar.jpg",
            NULL, NULL, &CubesTexture, NULL );
    
        // Describe the Sample State
        D3D11_SAMPLER_DESC sampDesc;
        ZeroMemory( &sampDesc, sizeof(sampDesc) );
        sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
        sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
        sampDesc.MinLOD = 0;
        sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
    
        //Create the Sample State
        hr = d3d11Device->CreateSamplerState( &sampDesc, &CubesTexSamplerState );
    
  • Chuck Walbourn
    Chuck Walbourn almost 10 years
    Since it's a .JPG, he should be using WICTextureLoader in DirectXTK, but yes... That's a good place to go. Be sure to look at Living without D3DX.
  • Ross Ridge
    Ross Ridge almost 10 years
    Is the picture really necessary?
  • Chuck Walbourn
    Chuck Walbourn almost 10 years
    Fine. No Humor on Stack Overflow. Got it.
  • Ross Ridge
    Ross Ridge almost 10 years
    It took up almost 50% of the screen space of your answer. No one is going to complain about a one line joke, but I think a picture that big should be an illustration that materially improves the understanding of your answer.
  • Chuck Walbourn
    Chuck Walbourn almost 10 years
    I think that image properly conveys the nature of D3DX and why it got deprecated. In any case, it looks like the mark-up language for SO doesn't let you resize image references... BTW, for those asking "what image?" it is this one.