DirectXTK - the DirectX Tool Kit
- Posted: Jun 11, 2012 at 6:00 AM
- 8,911 Views
- 1 Comment
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
In our continuing "Help you Build Metro" Monday series, Clint thought this project something you might find interesting. I've not highlight C++ projects very often, let along DirectX ones and so heartily agreed with him...
Over the Christmas break I spent some time porting the built-in XNA effects (BasicEffect, SkinnedEffect, etc.) to native C++ using Direct3D 11. Finding that strangely enjoyable, I went on to make a C++ version of SpriteBatch, and also ported the XNA Primitives 3D sample, built-in state objects, and helper vertex types. And my colleague Chuck Walbourn chimed in with some code for easily loading Direct3D 11 textures.
Get it here: DirectXTK.zip
- 3/5 - fixed bug in SpriteBatch with > 2048 sprites in a batch (thanks Pete Lewis!)
- 3/8 - added separate project files for Win8 Metro builds (thanks George Clingerman!)
- 5/2 - added SpriteFont implementation
Supported operating systems:
- Windows 8 Consumer Preview (both Metro and Desktop)
- Windows 7
- Windows Vista with DirectX 11 update
- Visual Studio 11 (currently in beta)
- Visual Studio 2010 plus the standalone Windows 8.0 SDK (you need the SDK to get the latest version of DirectXMath, which this code depends on)
How to use it:
- Unzip, load the solution into Visual Studio, and build it
- Link your program with the resulting static lib
- Add the Inc folder to your include path
To draw sprites:#include "SpriteBatch.h" using namespace DirectX; std::unique_ptr spriteBatch(new SpriteBatch(deviceContext)); spriteBatch->Begin(); spriteBatch->Draw(texture, XMFLOAT2(x, y)); spriteBatch->End();
To draw geometry using BasicEffect:#include "BasicEffect.h" using namespace DirectX; std::unique_ptr effect(new BasicEffect(device)); effect->SetWorld(world); effect->SetView(view); effect->SetProjection(projection); effect->SetTexture(cat); effect->SetTextureEnabled(true); effect->EnableDefaultLighting(); effect->Apply(deviceContext); deviceContext->IASetInputLayout(...); deviceContext->IASetVertexBuffers(...); deviceContext->IASetIndexBuffer(...); deviceContext->IASetPrimitiveTopology(...); deviceContext->DrawIndexed(...);
To draw geometric primitives:#include "GeometricPrimitive.h" using namespace DirectX; std::unique_ptr<GeometricPrimitive> teapot(GeometricPrimitive::CreateTeapot(deviceContext)); teapot->Draw(world, view, projection, Colors::CornflowerBlue);
See the readme inside the zip for more info.
From the readme;
This package contains the "DirectX Tool Kit", a collection of helper classes for writing Direct3D 11 code for Metro style apps, Windows 8 Desktop, and Windows 7 'classic' applications in C++.
This code is designed to build with either Visual Studio 11 which includes the Windows 8.0 SDK or Visual Studio 2010 with the standalone Windows 8.0 SDK installed using the "Platform Toolset" set to use the Windows 8.0 SDK. See the Visual C++ Team Blog <http://blogs.msdn.com/b/vcblog/archive/2012/03/25/10287354.aspx>. It makes use of the DirectXMath library and optionally the DXGI 1.2 headers from the Windows 8.0 SDK as well as other headers.
These components are designed to work without requiring any content from the DirectX SDK. For details, see "Where is the DirectX SDK"? <http://msdn.microsoft.com/en-us/library/ee663275.aspx>
Public Header Files:
SpriteBatch.h - simple & efficient 2D sprite rendering
SpriteFont.h - bitmap based text rendering
Effects.h - set of built-in shaders for common rendering tasks
GeometricPrimitive.h - draws basic shapes such as cubes and spheres
CommonStates.h - factory providing commonly used D3D state objects
VertexTypes.h - structures for commonly used vertex data formats
DDSTextureLoader.h - light-weight DDS file texture loader
WICTextureLoader.h - WIC-based image file texture loader
DirectXTK source files and internal implementation headers
Command line tool used to generate binary resources for use with SpriteFont
All content and source code for this package are bound to the Microsoft Public License (Ms-PL)
This is a native D3D11 implementation of the SpriteBatch helper from XNA Game Studio, providing identical functionality and API.
This is a native D3D11 implementation of a bitmap font renderer, similar to the SpriteFont type from XNA Game Studio, plus a command line tool (MakeSpriteFont) for building fonts into bitmap format. It is less fully featured than Direct2D and DirectWrite, but may be useful for those who want something simpler and lighter weight.
This is a native D3D11 implementation of the five built-in effects from XNA Game Studio, providing identical functionality and API:
- BasicEffect supports texture mapping, vertex coloring, directional lighting, and fog
- AlphaTestEffect supports per-pixel alpha testing
- DualTextureEffect supports two layer multitexturing (for lightmaps or detail textures)
- EnvironmentMapEffect supports cubic environment mapping
- SkinnedEffect supports skinned animation
This is a helper for drawing simple geometric shapes:
The CommonStates class is a factory which simplifies setting the most common combinations of D3D rendering states.
VertexTypes.h defines these commonly used vertex data structures:
DDSTextureLoader.h contains a simple light-weight loader for .dds files. It supports 1D and 2D textures, texture arrays, cubemaps, volume maps, and mipmap levels. This version performs no legacy conversions, so the .dds file must directly map to a DXGI_FORMAT (i.e. legacy 24 bpp .dds files will fail to load). It does support both 'legacy' and 'DX10' extension file header format .dds files.
For a full-featured DDS file reader, writer, and texture processing pipeline see the 'Texconv' sample and the 'DirectXTex' library
WICTextureLoader.h contains a loader for BMP, JPEG, PNG, TIFF, GIF, HD Photo, and other WIC-supported image formats. This performs any required pixel format conversions or image resizing using WIC at load time as well.
If you're developing with DirectX 11 this toolkit is for you...
Page Thumbnail courtesy of www.mtbs3d.com