Direct3D Tutorial Win32 Sample

This is the DirectX SDK's Direct3D 11 tutorial series updated to use Visual Studio 2012 and the Windows SDK 8.0 without any dependencies on legacy DirectX SDK content.

C++ (357.1 KB)
 
 
 
 
 
(15)
54,278 times
Add to favorites
10/12/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Tut 2 - Errors
    3 Posts | Last post Tue 7:04 PM
    • Hi,
      I have same problems as Conrad. But I am not bothered about Tutorial 1 as it builds and runs fine just by including #pragma comment(lib,"d3d11.lib").
      
      My problem is Tutorial 2. I can build it successfully by adding the 2 pragmas suggested by Conrad,i.e,
      #pragma comment(lib,"d3d11.lib") and
      #pragma comment(lib,"D3DCompiler.lib")
      
      But I can't make Tutorial 2 run. The .hlsl files produce the error:{Error X1507	failed to open source file: 'Tutorial02.fx'}.
      I tried to locate Tutorial02.fx in my computer but couldn't. Any idea where this file would be?
      
      Thanks!
    • Sorry i wrongly stated that Tutorial 2 builds ! Tutorial 2 doesn't build.
    • It seems quite likely you have a corrupt download because it builds fine if you download the full ZIP, open the Tutorials.sln in Visual Studio 2015, let it upgrade the projects to v140 and then build all. Alternatively, you can get the latest copy with VS 2015 projects included on GitHub: <https://github.com/walbourn/directx-sdk-samples>
  • Tut 2 - Build and Runtime Errors
    3 Posts | Last post October 19, 2015
    • Hi Chuck,
      
      I'm running the tutorials on Windows 7 SP1, with Visual Studio Community 2013, and the DirectX SDK (June 2010) installed.
      
      Tutorial 1 builds and runs properly, but only after adding this pragma to Tutorial01.cpp:
      #pragma comment(lib,"d3d11.lib")
      
      Without the above pragma, I get these errors:
      Error	1	error LNK2019: unresolved external symbol _D3D11CreateDevice@40 referenced in function "long __cdecl InitDevice(void)" (?InitDevice@@YAJXZ)
      Error	2	error LNK1120: 1 unresolved externals
      
      Tutorial 2 builds, but only after adding these pragma to Tutorial02.cpp:
      #pragma comment(lib,"d3d11.lib")
      #pragma comment(lib,"D3DCompiler.lib")
      
      Without the above pragma, I get these errors:
      Error	1	error LNK2019: unresolved external symbol _D3D11CreateDevice@40 referenced in function "long __cdecl InitDevice(void)" (?InitDevice@@YAJXZ)
      Error	2	error LNK2019: unresolved external symbol _D3DCompileFromFile@36 referenced in function "long __cdecl CompileShaderFromFile(wchar_t *,char const *,char const *,struct ID3D10Blob * *)" (?CompileShaderFromFile@@YAJPA_WPBD1PAPAUID3D10Blob@@@Z)
      Error	3	error LNK1120: 2 unresolved externals
      
      Also, to build Tutorial 2 I must exclude all three of these files from the build, (Tutorial02.fx, Tutorial02_PS.hlsl, Tutorial02_VS.hlsl), or I get these errors:
      Error	1	error X3501: 'main': entrypoint not found
      
      With the above changes, Tutorial 2 builds without errors, but I get this run-time error:
      The program can't start because D3DCOMPILER_47.dll is missing from your computer. Try reinstalling the program to fix this problem.
      
      Any ideas?
      
      Thank you.
    • This all sounds like problems with your VC project files (vcxproj). They should upgrade in place from VS 2012 to 2013 "as is". You may want to try the 2013 files for the tutorials on <https://github.com/walbourn/directx-sdk-samples> to see if those work for you. If not, you should try the VS Direct3D Game template for VS 2013 <http://blogs.msdn.com/b/chuckw/archive/2015/01/06/direct3d-win32-game-visual-studio-template.aspx> and take a look at the DirectX Tool Kit tutorials.
    • Hi Chuck,
      
      I just added the DirectX SDK (June 2010) Include and Lib/x86 paths to the VC++ Directories property of Tutorial 1 on my VS 2013 project, but the build still fails unless I include:
      #pragma comment(lib,"d3d11.lib")
      
      
      But d3d11.lib is in the DirectX SDK (June 2010) Lib/x86 path, so I'm not sure why the build fails without the above pragma, given that the DirectX SDK Lib/x86 path is now added to the project.
      
      However, I did not take the VC project files (vcxproj) from the Tutorial distribution. I created an empty Win32 project and then added these files to the project, from the Tutorial distro:
      
      directx.ico
      Resource.h
      Tutorial01.cpp
      Tutorial01.rc
      
      Does any of the above explain why the build fails without the pragma?
      
      I have another question about the vertex normals of 3D models imported from an external modeling program, into a DirectX project I'm building on VS 2013. This is probably not the place to ask you about that, so can you point me to a forum where you and I can have that discussion?
      
      Thank you.
  • weird overdraw with mdi applications
    2 Posts | Last post March 14, 2015
    • Hi Chuck,
      
      I placed this sample code within a mfc mdi application (wizard generated). I get weird results, there are some overdraws in the child frames and content while moving arround. This only occurs running with D3D_DRIVER_TYPE_HARDWARE, switching to D3D_DRIVER_TYPE_WARP is fine.
      
      Some screenshot:
      https://onedrive.live.com/redir?resid=26d5cbb201815da4!212&authkey=!AA-UPWXbSmrkGPE&v=3&ithint=photo%2cpng
      
      Are there any special window flags needed for mdi applications?
      
      For the record, I checked this on different Windows 7 machines running different Intel graphics (mostly HD4000), with different driver versions.
      And, there are the same results using the code in a c# mdi application via a clr dll.
      
      
    • The tutorial doesn't handle resize and is simple just to get the basics out of the way. You need to handle resizing to get the right behavior for an MDI. See this VS 2013 template for a more complete example of handling resize <http://blogs.msdn.com/b/chuckw/archive/2015/01/06/direct3d-win32-game-visual-studio-template.aspx>.
  • D3D11CreateDeviceAndSwapChain
    3 Posts | Last post February 03, 2015
    • Hi,Chuck,
      I'm running this tutorial01,it shows up the window and shut down in less than 1 second,I followed the code running,and find out the D3D11CreateDeviceAndSwapChain method was not successed,I'm using vs 2012 and windows 8.1,don'know why this happen.
    • You are likely building the Debug configuration which uses D3D11_CREATE_DEVICE_DEBUG. This requires the SDK debug layer be present. Visual Studio 2012 with the Windows 8.0 SDK does not have the Windows 8.1 version of the SDK Debug Layers, so all attempts to use debugging fail. This should be addressed in a future update, but at the moment if you are using Windows 8.1 you should use VS 2013 (the RC was released today). Alternatively, you can remove the use of the debug layer.
    • See this blog post for more details about where to get the right debug layer for your OS: <http://blogs.msdn.com/b/chuckw/archive/2012/11/30/direct3d-sdk-debug-layer-tricks.aspx>
  • Thanks for this, Chuck
    2 Posts | Last post February 03, 2015
    • The bit of errata about re-trying D3D11CreateDeviceAndSwapChain() calls with D3D_FEATURE_LEVEL_11_1 excluded got us up and running on stock Windows 7. I would have thought that feature levels that the OS doesn't know about would get skipped and the next FEATURE_LEVEL would be tried. The fact that it out-and-out fails if you pass in unknown feature levels in the array was really surprising.
    • Note that this is addressed in this blog post: <http://blogs.msdn.com/b/chuckw/archive/2014/02/05/anatomy-of-direct3d-11-create-device.aspx>
  • Can't use any file access in the sample
    2 Posts | Last post January 31, 2015
    • I am trying to write a buffer content to a file with the sample (any sample). First tried fopen or _fsopen, both can't open a valid file for writing, the errno is 13 (permission denied). Tried to use windows API CreateFile, but it would not even compile, says can't find the file definition, even I included the related header files.
      
      I am running this as a windows app (not even the phone version). I am wondering what is special about this sample here. Appreciate your quick response as I am stuck here.
    • This is the Win32 desktop version of the Direct3D tutorial. If you are targeting Windows Store or Windows Phone use that tutorial instead. https://code.msdn.microsoft.com/windowsapps/Direct3D-Tutorial-Sample-08667fb0. Windows Store apps have limited file write access which is why you get error 13. CreateFile is unavailable to Windows Store apps, but you can use CreateFile2. See https://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx
  • Can not see file?
    5 Posts | Last post August 31, 2014
    • When I am browsing the Code for Tutorial #2 both the VS and PS shader files are including the fx file. I can not see this fx file. Without this I can not get the code to build.
    • Do you mean when you try to run it? Tutorial02.fx is in the directory with the sample source.
    • I have the *.fx file which I found in the 2010 SDK samples. However when I try to build in VS2012 I am getting this error.
      
      1>------ Build started: Project: Direct3DSamples, Configuration: Debug Win32 ------
      1>FXC : error X3501: 'main': entrypoint not found
      1>  
      1>  compilation failed; no code produced
    • Redownload the sample package from MSDN Code Gallery. All configurations of it build fine in VS 2012. The Tutorial02.fx file is in the project but marked as "does to participate in build". The Tutorial02_VS.hlsl file includes "Tutorial02.fx" and is configured to use "VS" as the entry-point for a vs_4_0 profile. The Tutorial02_PS.hlsl file includes "Tutorial02.fx" and is configured to build "PS" as the entry-point for a ps_4_0 profile.
    • Thank You for the information. I had actually typed in all the code and created my own files. I didn't download and open the sample from the SDK browser. I was thinking of modifying this to use ps & vs 5_0 or 5_1. A while ago I was using Rastertek's website which was a great tutorial site for both DX10 and DX11 starting from basics and working through to advanced shaders and it even had its own section for 3D terrain rendering as well, but the site was recently taken down. It is very hard to find any truly good tutorial sites especially with good video tutorials.
  • Applications using DirectX TK stops with abort()
    5 Posts | Last post January 03, 2014
    • Hello,
      I got this message whenever I run an EXE that uses Directx TK from outside the Visual Studio:
      
      ---------------------------
      Microsoft Visual C++ Runtime Library
      ---------------------------
      Debug Error!
      
      Program: C:\DXTK_C++\C++\Debug\SimpleSample.exe
      R6010
      - abort() has been called
      (Press Retry to debug the application)
      ----------------------------
      
      When I use the DirectX TK in my application, I get it when I run the compiled exe, so I tried to compile the Directx TK Simple Sample but it also behaves in the same way.
      I forgot to mention that I use the DirectX TK 13/11/2012 and the Visual Studio 2012 on the Windows 7. Please I hope I get a quick reply.
      
      Thanks
    • Without a debug stack, it's very difficult to determine the root cause. You should run under the debugger and determine where this is getting triggered. Make sure you are building DirectXTK with the same version of your compiler as the rest of your app.
      
      You may want to move this discussion to the DirectXTK CodePlex site <http://go.microsoft.com/fwlink/?LinkId=248929>
    • Hello,
      Thank you very much,I was not expecting such a quick reply, really thanks.
      Concerning the debugging, after I ran the application in debugging mode, the file SpriteFont.cpp stops with a break message on the line 82 on this part of code exactly:
      
      SpriteFont::Impl::Impl(_In_ ID3D11Device* device, _In_ BinaryReader* reader)
      {
          // Validate the header.
          for (char const* magic = spriteFontMagic; *magic; magic++)
          {
              if (reader->Read<uint8_t>() != *magic) // Here it stops exactly
              {
                  throw std::exception("Not a MakeSpriteFont output binary");
              }
          }
      
      Sorry but the version I am using is not of 13/11/2012 but it is the one of 11/13/2013;
      I read in its associated documentation that it is however compatible with the Visual Studio 2012 and Windows 7.
      About the link you provided, I didn't manage to get there, since there is some kind of problem with it.
      I am a student and I has an assignment in which I preferred to benefit from the DirectX TK, so any help would be really appreciated.
      Thanks again.
    • You should enable C++ exception debugging and look at the callstack. You are probably providing the wrong kind of file to SpriteFont's constructor. See <https://directxtk.codeplex.com/discussions/471737> and <http://msdn.microsoft.com/en-us/library/vstudio/d14azbfh.aspx>
    • Note this question is not related to this particular sample. Please follow-up on the CodePlex <https://directxtk.codeplex.com/discussions>
  • Project incompatible with current edition of visual studio
    4 Posts | Last post February 07, 2013
    • tried to load this sample (Direct3D Tutorial Win32 Sample) into VS 2012 Ultimate and each project fails to load with the text written under the project name - "This project is incompatible with the current edition of Visual Studio" - running Windows 7 and have installed the Windows 8 SDK. 
    • The most likely reason you'd see this is if you were actually opening it with VS 2012 Express for Windows 8. Make sure you are opening it with the correct version of VS and that you are using VS 2012 RTM, not an RC. Try opening the solution explicitly with VS 2012 rather than click-launching it.
      
      It works fine for me with VS 2012 RTM and VS 2012 Update 1 using Windows 7 and Windows 8.
      
      
    • The other possibility is that you are actually trying to open a Windows Store app project with VS 2012 on Windows 7 which doesn't work either. Make sure you aren't trying to open the other sample "Direct3D tutorial sample" which is a Windows Store app.
    • I had accidentally tried to open the store version - thanks. 
  • Getting error MSB3073: The command "copy... error and not sure how to fix
    7 Posts | Last post January 24, 2013
    • Mr. Walbourn,
      
      I am getting the following error for project 2 through 6. I understand that it is trying to copy the dll to the debug folder, but I don't understand why it is failing. I unpacked the data into the Projects folder, double clicked the .sln file and when I hit "Build Solution", the following error appears for project 2 through 6:
      
      コマンドの構文が誤っています。<-- I live in Japan, but this says there is a syntax error
      7>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(204,5): error MSB3073: The command "copy “C:\Program Files (x86)\Windows Kits\8.0\redist\d3d\x86\D3DCompile*.DLL” “D:\Documents\Visual Studio 2012\Projects\Direct3D\C++\Debug\”
      7>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(204,5): error MSB3073: :VCEnd" exited with code 1.
      
      Sorry, I am a newbie with Visual Studio Express 2012. Any help would be appreciated. Thank you.
    • I updated the sample recently to use "$(WindowsSdkDir)redist\d3d\x86\D3DCompile*.DLL" which works on the "RTM" version, rather than the older $(WindowsSdkDir)\redist\d3d\x86\D3DCompile*.DLL" which only worked with "RC" and other pre-release versions. It looks like the 'correct' thing is happening on your system with the source. Do you have the files "C:\Program Files (x86)\Windows Kits\8.0\redist\d3d\x86\D3DCompile*.DLL" on your system?
    • Mr. Walbourn,
      
      I finally figured out the reason it was failing:
      copy “$(WindowsSdkDir)redist\d3d\x86\D3DCompile*.DLL” “$(TargetDir)”
      copy "$(WindowsSdkDir)redist\d3d\x86\D3DCompile*.DLL" "$(TargetDir)"
      (Quotation marks used are different on first line and second line
      as long as MSDN website doesn't screw them up)
      
      The double quotes used where:  	LEFT DOUBLE QUOTATION MARK 0x201C(UTF-16)
      I changed them to: QUOTATION MARK 0x0022(UTF-16)
      
      If you have any ideas why this would occur, it would be appreciated.
      I'm using Visual Studio Express 2012 Version 11.0.51106.01 Update 1
      on Windows 7 SP1. I live in Japan, so I was wondering if that has something
      to do with it as the LEFT DOUBLE QUOTATION MARK is used when typing in Japanese.
      
      Thank you for your time.
      
    • The quote changes are likely not portable across all locales. Also, the copy can return a code if it produces a prompt to overwrite. The last problem is that the multi-threaded build can lock the source file for some configurations, which seems to be fixed by setting "Treat Output as Content" to "Yes".
    • >The quote changes are likely not portable across all locales. 
      This might be true, however, I have the language setting set to English in Visual Studio, and I see no reason why it should use the local locale here。
      
      I submitted a bug report:
      https://connect.microsoft.com/VisualStudio/feedback/details/774293/visual-studio-express-2012-changes-quotes-in-command-line-under-custom-build-step-to-local-locale
    • Mr. Walbourn,
      
      I received an update to my bug report and here is the reply:
      
      "Thank you for creating a connect report to us. The sample has been fixed, but there is nothing we can do in the IDE for this case. The IDE does no quote manipulation or correction. If can think of something, feel free to share your thoughts and re-activiate this report."
      
      What do they mean by, "The sample has been fixed", was it a problem with the sample itself?
    • In this specific case, yes. The VCXPROJ file had the wrong kind of quotes in it.
1 - 10 of 14 Items