Nxna2
 All Classes Namespaces Functions Enumerations Enumerator Pages
Nxna2

Introduction

Nxna2 is primarily a cross-platform wrapper around OpenGL and Direct3D. Write your graphics code once with Nxna2 and get maximum portability!

Compiling

Compiling Nxna2 is simple. The easiest thing to do is this:

  1. Copy all the Nxna2 source to somewhere that your compiler can see it (perhaps within your code's project directory?)
  2. Create an empty .h and matching empty .cpp file. Add the .cpp file to your build.
  3. Within the .h file you created, enable the features you want (using #define), and at the very end #include the Nxna2.h file. For example:
    #define NXNA_ENABLE_MATH
    #define NXNA_ENABLE_RENDERER
    #define NXNA_ENABLE_INPUT
    #define NXNA_ENABLE_DIRECT3D11
    #include "Nxna2.h"
  4. Within the .cpp file add the following lines (be sure to modify the #include)
    #define NXNA2_IMPLEMENTATION
    #include "NameOfHeaderYouCreatedInStep2GoesHere.h"

Now whenever you need to use Nxna2, just #include the header file you created.

Initialization

The first thing to do is to create a new window, along with an OpenGL context if you intend to use the OpenGL renderer or a Direct3D device and device context if you intend to use Direct3D. It's your responsibility to set up the window and context/device. Nxna2 won't do it. That's so that you have complete control over the window creation process without Nxna2 getting in the way.

Next, you'll need to create a new GraphicsDevice object, which will act as a wrapper around whatever API you choose. You do that by filling out an Nxna::Graphics::GraphicsDeviceDesc struct and pass that to Nxna::Graphics::GraphicsDevice::CreateGraphicsDevice().

To create a new OpenGL device:

memset(&params, 0, sizeof(Nxna::Graphics::GraphicsDeviceDesc));
params.ScreenWidth = 640;
params.ScreenHeight = 480;

To create a Direct3D 11 device:

memset(&params, 0, sizeof(Nxna::Graphics::GraphicsDeviceDesc));
params.ScreenWidth = 640;
params.ScreenHeight = 480;
params.Direct3D11.Device = deviceThatYouCreatedInPreviousStep;
params.Direct3D11.DeviceContext = contextThatYouCreatedInPreviousStep;
params.Direct3D11.RenderTargetView = rtvThatYouAlreadyCreated;
params.Direct3D11.SwapChain = swapChainYouAlreadyCreated;

To be continued...

Basically, you just create a bunch of state objects by passing ...Desc to GraphicsDevice::Create...(), then call GraphicsDevice::Set...() with that new object. Then you create your index buffers and vertex buffer and constant buffers, set those two, and then render.

Other random stuff

Nxna2 has lots of objects, like BlendState, VertexBuffer, etc, that have unions with different OpenGL and Direct3D references in them. Generally you should treat those objects as completely opaque and not mess around with what is inside. But if you want to, go for it.