Archive for January, 2016

Bridging the Gap with C++/CLI

January 28th, 2016 No comments

A bit more than a week on and I’ve made some good progress on my project. I’ve spend a bit less time on adding things which while unfortunately does mean the screenshot in my last post is more or less unchanged but there’s been a number of changes behind the scenes.

  • The project has been split into three parts:
    • The engine DLL
    • An engine ‘runner’ / test application
    • Unit test project

This isn’t overly significant but provides a stable foundation for me to work with. One project is dedicated to all engine features and development, one for testing it, adding various custom binds and what not, and finally a unit test project that’ll ensure components of the engine remain in a working order.

Unit tests aren’t new to me but I haven’t actually used them before in C++. There isn’t much difference in implementation since Microsoft’s Unit Test Framework is solid and built right into Visual Studio.

Something that is entirely new to me however is C++/CLI. What I’ve been interested in doing for some time now is to develop a user interface with the engine running inside it as a small sub-region. This could be used for example, to create a level editor. C# .NET is excellent for developing user interfaces, however the engine is written in C++ language. There is the option of using COM Interop, but not only is this potentially slow, it’s also making things overly complicated.


A C++/CLI project is essentially Managed C++, capable of interacting with both native C++ and managed code, making it ideal for creating a bridging interface between the engine and any potential C# applications.

So far I’ve ‘ported’ most of the engine’s API calls over and am able to almost entirely replicate the image in my last post with a few small exceptions (primarily the second image) as I’m investigating an issue with vertex buffers and/or transforms (an interesting combination, no?)

I’ve also looked into designing a VSIX project which would basically allow me to create a WPF or Winforms ‘Toolbox Control’ so I can drag and drop an ‘Engine component’ onto a form and have it load. Unfortunately after an uneventful night this proved unsuccessful possibly due to the native library dependencies involved.

Fortunately I’ve had better luck simply hooking the engine up to the window handle of a WinForms component. As WPF only uses a single window handle for the main window, I’ve used a WindowsFormsHost component to still allow the flexibility of WPF while allowing me to hook up to a handle for this result (UI design not final ☺!):


Categories: Me, Programming Tags: , ,

DirectX 12

January 17th, 2016 No comments

It seems appropriate to start with a ‘Hello world’-style triangle:


Ever since details of DirectX 12 began to surface, I became interested in learning about it as most of my recent programming has been done through C# rather than C++, and the last time I worked with DirectX was very briefly with version 11 which had more of an emphasis of creating an abstraction layer above OpenGL/DirectX than an actual engine and prior to that, DirectX 9.

My main problem was hardware capability as my 2009-released AMD 5870 was simply not compatible with DirectX 12, but after purchasing a GTX 970 the opportunity arose, bundled with a two week holiday off work which was particularly motivating as already doing 40 hours of full-time programming a week reduces my appetite for after-hour hobby code projects. Fortunately it’s now been two weeks since I’m back at work and I’m still going.


This is the current state of the project. Visually it’s not very exciting and if anything makes me look awfully novice at any rate. Right now I’m putting most of my effort into developing a solid back-end that is capable of dynamically allocating resources when I request them, taking advantage of DirectX 12’s parallel capabilities where possible.

The latest feature implemented is the text renderer, which has the ability to either render to screen space or to world space. When rendered in screen space, it remains the same size when resizing the window and any transformations applied are done consistently through a Transform class object which is overridden for 2D positioning.

Buffers are particularly unique in this case, where I try to pool as much data as possible for a low frame overhead. In the above image there are three objects – 2 “squares” and 2 text objects. All are combined into a single index buffer, single vertex buffer and have each reserved a single constant buffer slot.

At the risk of overextending this post and allowing for future updates I’ll leave it at that, and rather than just posting about any progress I might go into further detail on some in-depth rendering techniques in the future as well.

Categories: Me, Programming Tags: , ,