locked
How to init a texture from a jpg file

    Question

  • Hi all:

      I want to display a picture on the surface on cube,so I use the "D3DX11CreateTextureFromFile()" function. But when I include "d3dx11tex.h", the error is

     "Error 1 error C2065: 'D3DX11_DEFAULT' : undeclared identifier".

    Who can tell me the reason. And where can I get a sample about create a texture from file? Thanks. 


    • Edited by Zoes Chen Tuesday, December 6, 2011 9:29 AM
    Tuesday, December 6, 2011 3:21 AM

Answers

  • There's a bit of confusion here because the Windows 8 SDK in the Windows 8 Developer Preview and the VS 11 Developer Preview includes D3DX*.h headers and D3DX*.lib import libraries, but does NOT include the D3DX*44*.DLL. This is because D3DX is deprecated and will not be available in the Windows 8 SDK--these headers and libraries will be removed in a future release. No version of D3DX is supported for Metro style applications.

    DDS files are the most efficient way to load textures at runtime for applications. DDS files can containmipmaps, cubemaps, volume maps, texture arrays, and are already typically converted to the appropriate pixel formats, block compressed, etc. Therefore the samples show how to load DDS files.

    In general you should prefer to only load DDS files for textures, and do all conversion at build time. This can be accomplished using the "Texconv" command-line tool or the "DirectXTex" library contained within it. See http://blogs.msdn.com/b/chuckw/archive/2011/10/28/directxtex.aspx

    There are some usage cases where you may want to load a single 2D image and create a non-mipmapped texture from it using some fairly inefficent but supported pixel format. This can be accomplished using the Windows Imaging Component (WIC). The "DirectXTex" code also uses WIC so you can refer to it for some examples on how to do this. Note that the "Texconv" sample and the DirectXTex library contained currently won't compile without modification in a Metro style application. A refreshed version of the sample will be released early next year which can be compiled in Metro style applications.

    Thursday, December 8, 2011 1:46 AM

All replies

  • From another thread:

    Note: to develop a Metro style application, you must use the Windows 8 SDK and NOT the DirectX SDK.

    Are you trying to use the DirectX SDK?

    -Jeff

     


    Jeff Sanders (MSFT)
    Tuesday, December 6, 2011 7:55 PM
    Moderator
  • Hi Jeff:

    I try it with the MSDN sample "Direct3D Tutorial Sample1-Lesson5", in this sample, it use a dds file as the texture.Now, I want to use another format file to instead it.

    Whether I can not use D3DX11.H in this project?How can I init a texture from file in WIN8 Metro style application ?

    Wednesday, December 7, 2011 2:29 AM
  • There's a bit of confusion here because the Windows 8 SDK in the Windows 8 Developer Preview and the VS 11 Developer Preview includes D3DX*.h headers and D3DX*.lib import libraries, but does NOT include the D3DX*44*.DLL. This is because D3DX is deprecated and will not be available in the Windows 8 SDK--these headers and libraries will be removed in a future release. No version of D3DX is supported for Metro style applications.

    DDS files are the most efficient way to load textures at runtime for applications. DDS files can containmipmaps, cubemaps, volume maps, texture arrays, and are already typically converted to the appropriate pixel formats, block compressed, etc. Therefore the samples show how to load DDS files.

    In general you should prefer to only load DDS files for textures, and do all conversion at build time. This can be accomplished using the "Texconv" command-line tool or the "DirectXTex" library contained within it. See http://blogs.msdn.com/b/chuckw/archive/2011/10/28/directxtex.aspx

    There are some usage cases where you may want to load a single 2D image and create a non-mipmapped texture from it using some fairly inefficent but supported pixel format. This can be accomplished using the Windows Imaging Component (WIC). The "DirectXTex" code also uses WIC so you can refer to it for some examples on how to do this. Note that the "Texconv" sample and the DirectXTex library contained currently won't compile without modification in a Metro style application. A refreshed version of the sample will be released early next year which can be compiled in Metro style applications.

    Thursday, December 8, 2011 1:46 AM
  • D3DX seems to include a lot of handy wrappers around the core DX functionality. The D3DX11CreateTextureFromFile method already mentioned is one example, but there are also various matrix building helpers like D3DXMatrixPerspectiveFovLH, D3DMatrixTranslation, etc.

    It's difficult to find Direct3D samples that don't use D3DX, and most of them use it extensively.

    I understand that none of this is fundamental functionality - we can always load textures ourselves, create matrices by hand etc. But on the other hand, a lot of this is stuff that lots of applications need to do. It's not entirely trivial to work out how to load a DDS file correctly without the help of D3DX11CreateTextureFromFile.

    Is there going to be a preferred library that we should be using now that D3DX is deprecated? (It's not even obvious from the documentation that D3DX is deprecated. Or at least, I've not yet found the page in the docs that says that it is. Perhaps we are supposed to infer this from it being under "Classic DirectX Graphics?")

    Thursday, December 29, 2011 11:22 AM
  • What if we're not intending to write a Metro style app? I'm writing an ordinary desktop app. What's the long term plan for the use of DirectX in such an application? Should I continue to build with the Windows 7 SDK and the DirectX SDK? Or is the intention that I will be able to move over to the Windows 8 SDK at some point?
    Thursday, December 29, 2011 11:25 AM
  • DirectXTex is available for Desktop applications, and there is a Windows 7 version on the blog link I provided. There is also a Desktop version of DDSTextureLoader.

    See http://msdn.microsoft.com/en-us/library/ee663275.aspx

     


    Wednesday, January 4, 2012 8:08 PM
  • Note that the only thing that really has to change in Texconv/DirectXTex code to build in the Metro style partition is to change the use of CreateFileW to use CreateFile2. You can use something like the following to let it compile for both Windows 8 only as is used by Metro style apps and for Windows 7:

    #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) 
       ScopedHandle hFile( CreateFile2( szFile, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0 ) );
    #else
        ScopedHandle hFile( CreateFileW( szFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 ) );
    #endif

    Tuesday, January 10, 2012 12:10 AM
  • There is now a "WICTextureLoader" module included in my "DirectXTex" package on my blog which does a fairly robust job of loading simple 2D textures directly from WIC-supported formats. If supported by the device, it can autogen mipmaps as well. Keep in mind that the image quality of the mimaps varies, and that any use of a IDirect3DDeviceContext is not "thread-safe". DDS and DDSTextureLoader is still very much the preferred solution for loading lots of high-quality texture resources from disk.

    http://blogs.msdn.com/b/chuckw/archive/2011/10/28/directxtex.aspx

    Tuesday, February 21, 2012 9:05 PM
  • You may want to review this post w.r.t. to D3DX replacements.
    Wednesday, August 21, 2013 6:24 AM