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)
3.8 Star
63,328 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

    1 Posts | Last post Thu 10:58 PM
  • Is this a bug ? [tutorial 6]
    1 Posts | Last post January 30, 2017
    • Hi,
      in the vertex shader of tutorial n°6, the normal vector is transformed:
      output.Norm = mul( float4( input.Norm, 1 ), World ).xyz;
      I think this should be 
      output.Norm = mul( float4( input.Norm, 0 ), World ).xyz;
      otherwise the normal vector is wrong when the World matrix has translation components.
      Or am I missing something ?
  • is there a d3d 12 version of this tutorial?
    3 Posts | Last post October 18, 2016
    • with the difference of d3d 11 VS 12?
    • First a disclaimer: DirectX 12 is an expert API which builds on knowing the ins & outs of DirectX 11. DirectX 12 is an extremely low-level API designed for graphic experts who have a solid understanding of the architecture of modern GPU hardware, and can essentially write the DirectX 11 Runtime from scratch. Both DirectX 11 and DirectX 12 provide access to the same hardware features on Windows 10, but drive the hardware in different ways which can allow a well-optimized DirectX 12 engine to achieve much lower CPU overhead than in DirectX 11.
    • The 'official' introductory DirectX 12 samples for UWP and Win32 desktop are on GitHub <>, specifically the D3D12HelloWorld samples.
      You can also find introductory DirectX 12 samples for UWP on <>.
      I'd recommend taking a look at the Direct3D 12 Game VS Templates <> and the DirectX Tool Kit for DirectX 12 tutorials <>.
  • Tut 2 - Errors
    3 Posts | Last post July 26, 2016
    • 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?
    • 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: <>
  • 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 <> to see if those work for you. If not, you should try the VS Direct3D Game template for VS 2013 <> 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:
      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:!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 <>.
  • 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: <>
  • 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: <>
  • 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. 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
  • 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>  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.
1 - 10 of 17 Items