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++ (354.6 KB)
 
 
 
 
 
(14)
26,358 times
Add to favorites
11/18/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Thanks for this, Chuck
    1 Posts | Last post January 31, 2014
    • 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.
  • 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>
  • D3D11CreateDeviceAndSwapChain
    2 Posts | Last post September 09, 2013
    • 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.
  • 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.
  • Few questions about Tutorial01
    7 Posts | Last post January 13, 2013
    • Hi Chuck.
      1)Can we do not using global variable, by changing function input parameters for communication via local?
      2)In DX9 book at
      ShowWindow(g_hWnd, nCmdShow);
      //UpdateWindow(g_hWnd);
      return S_OK;
      UpdateWindow is present. Why in this sample it don't?
      3)DX9 book said that COM links must be set NULL after release. Why they don't in sample? And in VS2010/2012 it might now nullptr?
      
      Thanks.
      
      P.S.
      In InitDevice(void) you can return hr because on begin you set it to S_OK.
    • (1) Many of the DirectX SDK samples use globals for simplicity. Better practice would be to use parameters or perhaps make use of C++ objects.
      
      (2) UpdateWindows forces a WM_PAINT. That's not necessary in the samples. It could well be a left-over from some workaround for an older version of Windows in that book.
      
      (3) It's always good practice to do 'pointer sanitation' of setting 'dangling' pointers to 0 explicitly. It's not required but it can be a safety measure. Many DirectX SDK samples make use of a SAFE_RELEASE macro to do this conviently, but that's no in the tutorial to keep the code a bit more simple to follow.
      
      #ifndef SAFE_RELEASE
      #define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=nullptr; } }
      #endif
      
      Of course, an even better solution is to use a COM smart-pointer like ATL's CComPtr or WRL's ComPtr.
      
      'nullptr' is the C++11 type-safe version of the classic "NULL" #define. They mean the same thing, but 'nullptr' is the modern version.
    • 1), 2)Got it.
      3)During evolution of tutorial I see that macro way, but last time see templated class way. Like in your Win8UI sample "Media engine native C++ video playback sample".
      
      Smart-pointer sounds good, but to early to me, with Express Edition and without <atlbase.h> :(
      When in VS2008 EE I work with <MsHTML.h>, I have some internal COM smart-pointer 
      (for e.g. provided for this types)
      	MSHTML::IHTMLElementCollectionPtr
      	MSHTML::IHTMLElementPtr
      
      Can I use some near approach in this tutorial with Visual Studio Express 2012 for Windows Desktop?
      
      New short question. {0} and ZeroMemory using. Did you have some rules when you choose one of that?
      
      I read Raymond Chen explanation http://blogs.msdn.com/b/oldnewthing/archive/2005/06/28/433341.aspx , so in my version of this sample I prefer to use ZeroMemory.
      
      P.S.
      I too in RECT and D3D11_VIEWPORT cases set only per members initialisation.
      But actually not in all cases per members initialization get a succesfull call of function.
      In my experience I take not succesfull (not run-time exception, app just do nothing) call of ChangeDisplaySettings (in DX9 app) when only simple set to all member of DEVMODE struct.
      {0} or ZeroMemory required before setting
      dm.dmSize = sizeof(DEVMODE);
      dm.dmPelsWidth = 640;
      dm.dmPelsHeight = 480;
      dm.dmBitsPerPel = 32;
      dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
      
      ChangeDisplaySettings(&dm, CDS_FULLSCREEN)
    • I train with feature levels and DirectX 10+ family, and founded that only in DirectX10_1 (maybe the reason only in this feature level) case I can see full screen in Virtual Machine (Virtual Box) of Windows 8 Enterprise Evaluation (Build 9200) by pressing Alt+Enter, in stand alone EXE. In VS (by F5, or Ctrl+F5) I do not enter in full screen mode, when close app I see next in output window DXGI ERROR: IDXGISwapChain::GetContainingOutput: The swapchain's adapter does not control the output on which the swapchain's window resides. [ MISCELLANEOUS ERROR #80: ]
      First-chance exception: Microsoft C++ exception: _com_error 
      
      On host machine I take full-screen in all variation:
      WinMain_DX11_1Hello.exe
      WinMain_DX11Hello.exe
      WinMain_DX10_1Hello.exe
      WinMain_DX10Hello.exe
      
    • With VS 2012, you can make use of the WRL template ComPtr.
      
      See DXGI Best Practices <http://msdn.microsoft.com/en-us/library/windows/desktop/ee417025.aspx> for recommendations about supporting full-screen.
    • During understanding the logic of DirectX in WinStore App I return to this topic, so I got it.
      Next what I have now (sample in Desktop App):
      //DxGraphics.h
      
      #include <wrl.h>
      #include <d3d11_1.h>
      
      #pragma comment(lib, "d3d11.lib")
      
      namespace DX
      {
      	inline void ThrowIfFailed(HRESULT hr)
      	{
      		if (FAILED(hr))
      		{
      			// Set a breakpoint on this line to catch DX API errors.
      			throw hr;
      		}
      	}
      }
      
      class DxGraphics
      {
      private:
      	Microsoft::WRL::ComPtr<ID3D11Device>            m_d3dDevice;
      	Microsoft::WRL::ComPtr<IDXGISwapChain>          m_swapChain;
      	Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  m_d3dRenderTargetView;
      	Microsoft::WRL::ComPtr<ID3D11DeviceContext>     m_d3dContext;
      	D3D_FEATURE_LEVEL                               m_featureLevel;
      public:
      	DxGraphics();
      
      	void InitDevice4DesktopApp(HWND hOutputWindow);
      	void Render();
      
      	~DxGraphics();
      };
      
    • In DxGraphics.cpp at void InitDevice4DesktopApp(HWND hOutputWindow); I have next approach
      //...
      	D3D_DRIVER_TYPE driverType;
      	ComPtr<IDXGISwapChain> swapChain;
      	ComPtr<ID3D11Device> device;
      	ComPtr<ID3D11DeviceContext> context;
      
      	HRESULT hr = S_OK;
      	for(UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
      	{
      		driverType = driverTypes[driverTypeIndex];
      		hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels,
      			D3D11_SDK_VERSION, &sd, &swapChain, &device, &m_featureLevel, &context);
      		if(SUCCEEDED(hr))
      			break;
      	}
      	DX::ThrowIfFailed(hr);
      
      	// Get the Direct3D swapChain, device and context interfaces.
      	DX::ThrowIfFailed(
      		swapChain.As(&m_swapChain)
      	);
      
      	DX::ThrowIfFailed(
      		device.As(&m_d3dDevice)
      	);
      
      	DX::ThrowIfFailed(
      		context.As(&m_d3dContext)
      	);
      //...
      see more at DWriteHelloWorld sample http://code.msdn.microsoft.com/windowsapps/DWriteHelloWorld-760793d2 (WinStore App).
  • D3DCompileFromFile not found..?
    2 Posts | Last post December 13, 2012
    • Hello, 
      I downloaded the samples and tried to run them, but the only one working is n°1.
      All the others fail to build due to a 'D3DCompileFromFile': identifier not found error. I have Win8 SDK installed, but I don't really know what I'm doing wrong..
      Thank you for your time
    • This most likely indicates that you have your include paths setup in a way to use the older DirectX SDK version of 'd3dcomplier.h' rather than the Windows SDK version. See which version is being referenced.
  • launch "exe" examples
    3 Posts | Last post September 19, 2012
    • Hi!
      I apologize for maybe stupid question. (I am a novice)
      
      I have the following problems:
      I may run examples Tutorial 1 - 7 visual studio 2012 (debug, realise mode) and they are working good. But when I try to run ready "exe" files start properly only Tutorial01.exe, others (eg Tutorial02.exe) start with a error (I suspect that it related to "hr = CompileShaderFromFile (L" Tutorial02.fx "," VS "," vs_4_0 ", & pVSBlob);").
      What could be the problem?
    • It's probably the current working directory. The .fx file needs to be in the 'current' directory. The easy solution is to copy the .fx file to the same directory as the EXE.
    • Thank you so much! It works.
  • Texture Coordinates
    1 Posts | Last post May 19, 2012
    • In the original Tutorial07, the orientation of the texture coordinates was arbitrary since the sealfoor.dds texture doesn't really have a clear orientation.
      
      However, if you apply a texture with text, the result is pretty strange looking. I updated the sample so that if you use something with text, the cube looks more or less like you'd expect it to with an 'oriented' texture