Support development of RCC++ through GitHub Sponsors or Patreon

RuntimeCompiledCPlusPlus Dear ImGui and DirectX11 Tutorial
You can also find this tutorial in the devlog post Runtime Compiled C++ Dear ImGui and DirectX11 Tutorial.
This tutorial takes a small DirectX11 project, the Dear ImGui Example, and adds Runtime Compiled C++ to it. This enables us to edit the code at runtime and see the results live, without recompiling and restarting the project.
This is a Windows only project but both Dear ImGui and Runtime Compiled C++ are cross platform. Thanks to Jonathan Bleeker and Milviz for funding this tutorial.
Runtime-Compiled C++ (RCC++) is a way to reliably make major changes to C++ code at runtime and see the results immediately. It's aimed at games development but could be useful in any industry where turnaround times are a bottleneck.
https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus
RCC++ is primarily designed to shorten iteration times in development - developers can build their project, run it, make changes during runtime and see the results in a few seconds.

Getting the tutorial code
The complete finished code for this tutorial, including Dear ImGui and RuntimeCompiledCPlusPlus can be found on GitHub as RCCpp_DX11_Example. Each chapter of the tutorial has a branch with the changes up to that point, so the implementation can be followed step by step.
A similar cross platform example using Dear ImGui with GLFW and OpenGL is available on GitHub as RCCpp-DearImGui-GLFW-example.
RCC++ Dear ImGui and DirectX Tutorial Video Part 1: Introduction and Getting the Code
The easiest way to get hold of the example code if you have git is to run the following command using a shell you can run git:
git clone --recursive https://github.com/dougbinks/RCCpp_DX11_Example
You can download git for windows from https://git-scm.com/download/win, and use the right click menu in Windows File Explorer to "Git Bash here" and then run git commands.
This will create the directory RCCpp_DX11_Example and get the latest source code, using the --recursive option to download the Dear ImGui and RuntimeCompiledCPlusPlus code, which have been included in the tutorial repository as submodules. If you want to run further git commands from the command line you'll need to cd into the directory:
cd RCCpp_DX11_Example
Alternatively you can use a git GUI program to get the code, most of these will automatically download the git submodules.
If you download the code via the "Download ZIP" approach, you'll also need to download RuntimeCompiledCPlusPlus and Dear ImGui into the RuntimeCompiledCPlusPlus and imgui folders. The correct versions can be found by clicking on the RuntimeCompiledCPlusPlus and imgui folders you see on the front page of the RCCpp_DX11_Example GitHub page as below.
The project is split into several branches to allow you to navigate to important points in its development, notably:
- Project_Setup - branch - .zip
- Working_RCC++ - branch - .zip
- RCC++_With_ImGui - branch - .zip
- RCC++_With_D3D - branch - .zip
- RCC++_With_D3D_Library - branch - .zip
- master (latest code). - branch - .zip
With git the following command can be used to change branches (using the RCC++_With_ImGui branch as an example):
git checkout RCC++_With_ImGui
Initial Project Setup with Visual Studio
In this section I'm going to give an overview of the steps needed to setup a Visual Studio solution and projects with the files needed for RCC++, using the Dear ImGui example app as a basis.
Both Dear ImGui and RCC++ are on GitHub, and both provide Visual Studio project files. However, the project files need to be updated to match the version of VS in use. A simple approach to the project setup would be to fork each repo, but for this tutorial we copy the project files into another folder so we can keep the source repos clean of any changes.
This is somewhat tedious so I recommend you skip to the next chapter - if you're following along with the code you can grab the starting project on branch Project_Setup in your git clone using:
git checkout Project_Setup
RCC++ Dear ImGui and DirectX Tutorial Video Part 2: Project Setup
For detailed steps see the repo commit history on branch Project_Setup.
The principal steps are to create a new Visual Studio solution with the example_win32_directx11 Dear ImGui example and the RCC++ libraries. RCC++ consists of two libraries:
- the RuntimeCompiler which handles compiling; and
- RuntimeObjectSystem which handles automatically compiling the appropriate files (this will be detailed later) whenever a file is changed.
A useful tip is that Visual Studio projects consist of two files - the .vcxproj and .vcxproj.filters file. The other VS files aren't required to setup a project. In the following instructions, and in the example repository, we copy the project files we need rather than create them from scratch and add the required code, though for RCC++ the later approach is fairly simple.
The setup consists of the following steps:
- Set up a new repo and add RCC++ and Dear ImGui as submodules. If git isn't being used this step would be to create an empty directory for the project and download RCC++ and Dear ImGui into separate sub-directories
- Test the example code for both works. This requires the projects to be updated to an installed version of Visual Studio which we're prompted for on opening the solution for the first time. Discard the project changes once tested
- Create an empty Visual Studio Win32 Console project, and delete the project as we'll be making our own
- Copy the example code from
imgui\examples\example_win32_directx11 root folder; main.cpp, example_win32_directx11.vcxproj and example_win32_directx11.vcxproj.filters need to be copied.
- Rename
example_win32_directx11.vcxproj.* in the root folder to RCCpp_DX11_Example.*, the same names as the project we deleted above.
- Change the following paths in the project files
RCCpp_DX11_Example.vcxproj.* we just renamed using a text editor with search and replace:
- Replace
..\.. with imgui
- Replace
.. with imgui\examples
- Copy the RCC++ project files (
*.vcxproj and *.vcxproj.filters) from folders RuntimeCompiledCPlusPlus\Aurora\RuntimeCompiler and RuntimeCompiledCPlusPlus\Aurora\RuntimeObjectSystem to our root folder. Change the following paths using a text editor with search and replace
- In
RuntimeCompiler.vcxproj and RuntimeCompiler.vcxproj.filters ( renamed from RuntimeCompiler_VS2010.* ):
- Replace
<ClCompile Include=" with <ClCompile Include="RuntimeCompiledCPlusPlus\Aurora\RuntimeCompiler\
- Replace
<ClInclude Include=" with <ClInclude Include="RuntimeCompiledCPlusPlus\Aurora\RuntimeCompiler\
- In
RuntimeObjectSystem.vcxproj and RuntimeObjectSystem.vcxproj.filters:
- Replace
<ClCompile Include=" with <ClCompile Include="RuntimeCompiledCPlusPlus\Aurora\RuntimeObjectSystem\
- Replace
<ClInclude Include=" with <ClInclude Include="RuntimeCompiledCPlusPlus\Aurora\RuntimeObjectSystem\
- For the following project changes, when opening the project properties (right clicking on a project in the Solution Explorer and selecting properties) pages make sure to set the configuration to
All Configurations and Platform to All Platforms.
- Add the projects to our solution and switch the platform toolset to our version of Visual Studio: version 142 for Visual Studio 2019
- Add the include directories to the RCC++ and imgui by changing the C/C++ General 'Additional Include Directories' to read:
imgui;imgui\examples;RuntimeCompiledCPlusPlus\Aurora\RuntimeObjectSystem;RuntimeCompiledCPlusPlus\Aurora\RuntimeCompiler;%(AdditionalIncludeDirectories).
- Setup project dependencies - right click on the Solution in the Solution Explorer and select Project Dependencies. For the project
RCCpp_DX11_Example the RuntimeCompiler and RuntimeObjectSystem should be selected as 'depends on'.
- Right click on all the projects
RCCpp_DX11_Example, RuntimeCompiler.lib and RuntimeObjectSystem.lib, in General tab change the output directory to: $(SolutionDir)build\$(PlatformTarget)\$(Configuration)\ and the Intermediate Directory to: $(SolutionDir)build\intermediates\$(ProjectName)\$(PlatformTarget)\$(Configuration)\.
- Right click on the
RCCpp_DX11_Example project and select Properties. Under the Linker General settings add the output directory as an Additional Library Directory by entering $(OutDir) before the other directories.
- In the Linker Input properties for the
RCCpp_DX11_Example project add RuntimeCompiler.lib and RuntimeObjectSystem.lib as link Additional Dependencies.
The code up to this point is available in the example from the branch Project_Setup at https://github.com/dougbinks/RCCpp_DX11_Example/tree/Project_Setup. This runs the Dear ImGui example code and has the RuntimeCompiler and RuntimeObjectSystem libraries linked, but has no RCC++ code setup as yet.
Working RCC++
The next step after the project setup is to get RCC++ working with the minimal code required.
RCC++ Dear ImGui and DirectX Tutorial Video Part 3: Working RCC++
For detailed steps take a look at the repo commit history on branch Working_RCC++.
The basic code to initialise and cleanup RCC++ is:
main.cpp
#include "RuntimeObjectSystem.h"
// headers from our example
#include "StdioLogSystem.h"
// RCC++ Data
static IRuntimeObjectSystem* g_pRuntimeObjectSystem;
static StdioLogSystem g_Logger;
// Forward declarations of RCC++ helper functions
bool RCCppInit();
void RCCppCleanup();
// Main code
int main(int, char**)
{
// Create application window
//...
// Initialize RCC++
RCCppInit();
// Initialize Direct3D
//...
// Cleanup
RCCppCleanup();
//...
}
bool RCCppInit()
{
g_pRuntimeObjectSystem = new RuntimeObjectSystem;
if( !g_pRuntimeObjectSystem->Initialise(&g_Logger, NULL) )
{
delete g_pRuntimeObjectSystem;
g_pRuntimeObjectSystem = NULL;
return false;
}
return true;
}
void RCCppCleanup()
{
delete g_pRuntimeObjectSystem;
}