Archive for the ‘Programming’ Category

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: , ,

DNS Switcher

January 1st, 2014 No comments

I had a bit of play with streaming services today and was interested in getting Netflix working on a media server I’ve got set up. After some confusion, tinkering and satisfaction everything was eventually working. The only problem was that now Australian based streaming services were no longer available.

A workaround was to manually edit the DNS address on the device, but doing this with a TV remote isn’t the most sophisticated of methods. The next idea was to simply point the DNS address to the router and have that changed, much faster on a computer. There was still the repetition and problematic approach of having to log in and fetch one of the two DNS addresses aside from trying to memorise them.


The solution ended up being a little C# utility, which would log into the router automatically and perform the necessary changes using the built in features of the WebBrowser class using a very simple 2 button interface. All I got to do now is fire up the program, hit the show I want to watch and after the router resets I’m good to go!

It’s interesting to program something that not only works but actually solves a real-world practical problem to make life easier. Here’s hoping there’s more where that came from.

Categories: Programming Tags: , , ,

Fog Implementation

December 6th, 2013 No comments













I wanted to go into some detail how the fog component in the RTS project worked, which was one of the more specialised features you don’t find in other genres. I decided to use a three-stage implementation.

  • Undiscovered
  • Discovered
  • Revealed

The fog would begin as being completely undiscovered. As units explore, areas become revealed. Then, if a unit leaves a discovered area, instead of covering the area back up completely, the area would become only partially shrouded – only the landscape is visible and no potential hostile entities are.

The fog itself is essentially a low-resolution texture, 64 x 64 that is orthogonally projected over the entire terrain, as well as being rendered on top of the minimap texture, which means I’ve separated static (terrain) and dynamic (icons, units, other icons) draw calls

To reveal areas of the map, each unit and building sends a raycast upwards which is masked to only hit the fog’s physical layer which covers the entire map. The hit point is then converted into a texture coordinate by dividing the world position by the terrain size. Because it’s orthogonally projected, this results in a perfect representation of a pixel using the correct coordinates. This pixel and its neighbour’s colours are then set to black with no alpha, to allow it to fade in from the surrounding shroud.


The downside to this is that this is performed on the CPU entirely with the obvious exception of the projection being drawn. To somewhat solve the problem of a lot of units causing a lot of stress on the CPU from raycasts, raycasts are performed for 10% of all units per frame, which still results in a fast fog reaction. Because the fog resolution is relatively small, only 64 x 64, areas are revealed in a grid-like pattern which in this case is fine. A smooth and gradual reveal would most likely be impractical using my implementation due to the sheer number of raycasts and texture resolution of the fog layer.

One problem this has caused is that the way Unity handles projections is rather odd. As can be seen from the second image, projections are performed on a per-material basis which is causing artifacts on textures themselves. For example, the bridge has bright spots which match the area of the fog layer that is revealed. A fix for this would most likely also combat the aforementioned downside, by utilizing a pixel shader on the GPU that handles my own implementation without the use of texture projection. This however would not allow the raycasting implementation and I would most likely have to use  unit positions in static buffers to feed directly into GPU memory.

Web Development

November 21st, 2013 No comments

It’s been a little while since the last update, mainly for two separate reasons. The first being I have had second degree burns on my shoulder for a week which wasn’t helping motivation to code let alone use a computer or do anything else, and while I didn’t do nothing I chose to take a bit of time off from any side hobbies until I could get to a point they’d be fun to code again.

The second part goes for a website I’ve been creating for someone that’s essentially going to be used for a small community group, and since this is a bit more than a hobby project I’ve been prioritizing it’s completion has a somewhat larger meaning. The thing is I’ve never actually dealt much with web development. I have a blog which I occasionally tinker with, and I have had some work done with SQL databases for non-web based applications. The nice thing the deadline is very relaxed; essentially ‘get it done before the end of the year or something’ so it’s given me ample time to explore some features. I’ve been using jQuery, the Facebook API, the Google Maps v3 API, more PHP and a fair bit of CSS.

I’m quite content with the progress I’m making, having developed a user system that synchronizes loosely with the Facebook API (only for notifications, which work nicely) as well as varying levels of access, and of course, secure, salted and encrypted passwords. There’s a bit more to go – I’d estimate I’m just over the halfway point now with a fair bit of that second-half simply being polishing things up, and I might post a link up once I’ve finished it. I’ll post a bit more later on how I’m dividing up my workload so if anyone follows the posts then you’d have a better understanding of when to expect things.

Categories: Me, Programming Tags: , , , ,