SpriteBatch and BasicEffect for C++ Direct3D 11

Published March 02, 2012
Advertisement
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
Supported operating systems:

  • Windows 8 Consumer Preview (both Metro and Desktop)
  • Windows 7
  • Windows Vista with DirectX 11 update

    Supported compilers:

    • 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"
        #include 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"
        #include 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"
        #include using namespace DirectX; std::unique_ptr teapot(GeometricPrimitive::CreateTeapot(deviceContext)); teapot->Draw(world, view, projection, Colors::CornflowerBlue);
        See the readme inside the zip for more info.aggbug.aspx?PostID=10276733

        Source
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement