Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    83
  • comments
    0
  • views
    66937

SpriteBatch and BasicEffect for C++ Direct3D 11

Sign in to follow this  
shawnhar

1521 views

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
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!