CNA – It’s C++ XNA

XNA is still one of the most popular indie game development frameworks years after being abandoned by Microsoft. The popular C# gamedev project has been kept alive by the MonoGame and FNA frameworks, which are still being used to create popular indie games. Now there is a new XNA based project – CNA, a C++ 23 reimplementation of XNA.

Right now it is still very much a work in progress, although it is already capable of running the majority of XNA samples. The goals of the project are as follows:

  • Recreate the XNA developer experience in native C++.
  • Provide a native C++ path for teams that like the XNA/MonoGame model but need non-managed runtime/toolchain control.
  • Mirror core XNA namespaces and API patterns while implementing them incrementally.
  • Decouple gameplay-facing API from rendering backend implementation details.
  • Enable one high-level API surface across different rendering technologies.
  • Keep SDL/OpenGL/Vulkan-level concerns behind framework abstractions.

Here is a sample simple XNA application written in C++ using CNA:

#include <memory>

#include "Microsoft/Xna/Framework/Game.hpp"
#include "Microsoft/Xna/Framework/Color.hpp"
#include "Microsoft/Xna/Framework/Graphics/GraphicsDeviceManager.hpp"
#include "Microsoft/Xna/Framework/Graphics/SpriteBatch.hpp"
#include "Microsoft/Xna/Framework/Graphics/Texture2D.hpp"

using namespace Microsoft::Xna::Framework;
using namespace Microsoft::Xna::Framework::Graphics;

class MyGame final : public Game {
public:
    MyGame()
        : graphics_(this)
    {
    }

protected:
    void LoadContent() override
    {
        spriteBatch_ = std::make_unique<SpriteBatch>(getGraphicsDeviceProperty());
        logo_ = std::make_unique<Texture2D>("assets/logo.png", getGraphicsDeviceProperty());
    }

    void Update(GameTime& gameTime) override
    {
        (void)gameTime;
        // Update game state here.
    }

    void Draw(const GameTime& gameTime) override
    {
        (void)gameTime;

        auto& device = getGraphicsDeviceProperty();
        device.Clear(CornflowerBlue);

        spriteBatch_->Begin();
        spriteBatch_->Draw(*logo_, 100.0f, 80.0f);
        spriteBatch_->End();

        device.Present();
    }

private:
    GraphicsDeviceManager graphics_;
    std::unique_ptr<SpriteBatch> spriteBatch_;
    std::unique_ptr<Texture2D> logo_;
};

int main()
{
    MyGame game;
    game.Run();
    return 0;
}

Key Links

CNA Homepage

CNA GitHub Repository

CNA Samples Repository

You can learn more about CNA – XNA in C++ 23 – in the video below.

Scroll to Top