The idea behind this repo is for it to be used as a minimal starting point for development of a game, demo or prototype.
It utilizes SDL2 for the windowing system, bgfx (by @bkaradzic) for the graphics library and Dear ImGui (by @ocornut) for the user interface.
The code in main.cpp
is derived from two excellent bgfx
tutorials (hello-bgfx by Phil Peron and bgfx-ubuntu by Sandeep Nambiar). I highly recommend checking them out.
This repo does not directly include any of these dependencies. Instead, CMake is used to download and install them so this project can use them. This is handled through the use of a superbuild.
To begin with create a directory to hold the repo:
mkdir sdl-bgfx-imgui-starter
cd sdl-bgfx-imgui-starter
Then clone the repo:
git clone https://github.com/pr0g/sdl-bgfx-imgui-starter.git .
This project comes with a superbuild CMake script which will build all third party dependencies and the main application in one step. The third party dependencies are built and installed to a separate build folder in the third party directory. To achieve this CMake must be installed on your system (the repo has most recently been tested with CMake version 3.24
).
Note: It is possible to build the third party dependencies separately, but the configure scripts described below now default to use
-DSUPERBUILD=ON
(as this is the simplest and most common workflow). If you do wish to build the third party dependencies separately, please see the third party README for full instructions on how to do this.Note: When building the dependencies, the libraries are by default self contained in the repo and are not installed to the system.
Shaders for bgfx
must be compiled to be loaded by the application (the starter has an incredibly simple shader supporting vertex colours). See compile-shaders-<platform>.sh/bat
for details. shaderc
is built as part of bgfx
when first building the repo and is used to compile the shaders.
Note: A number of
configure-<generator>.bat/sh
files are provided to run the CMake configure commands.Ninja
is preferred as it's consistent across macOS, Linux and Windows (and it's very fast), any generator should work though. For example there's aconfigure-vs-19/22.bat
for generating a Visual Studio 2019 or 2022 solution.
configure-vs-19.bat
, configure-vs-22.bat
or configure-ninja.bat
located in the root directory to generate the build files required for the project.cmake --build build\debug-ninja
and/or cmake --build build\release-ninja
to compile the project using Ninja or cmake --build build\vs<year> --config Debug
and/or cmake --build build\vs<year> --config Release
if using the Visual Studio generator.compile-shaders-win.bat
located in the root directory to build the shaders.build\debug-ninja\sdl-bgfx-imgui-starter.exe
or build\release-ninja\sdl-bgfx-imgui-starter.exe
if using Ninja or build\vs<year>\Debug\sdl-bgfx-imgui-starter.exe
or build\vs<year>\Release\sdl-bgfx-imgui-starter.exe
if using Visual Studio../configure-make.sh
or ./configure-ninja.sh
located in the root directory to generate the build files required for the project (prefer Ninja if possible as it's much faster).cmake --build build/debug-<generator>
and/or cmake --build build/release-<generator>
to compile the project../compile-shaders-macos.sh
located in the root directory to build the shaders../build/debug-<generator>/sdl-bgfx-imgui-starter
or ./build/release-<generator>/sdl-bgfx-imgui-starter
../configure-make.sh
or ./configure-ninja.sh
located in the root directory to generate the build files required for the project (prefer Ninja if possible as it's much faster).cmake --build build/debug-<generator>
and/or cmake --build build/release-<generator>
to compile the project../compile-shaders-linux.sh
located in the root directory to build the shaders../build/debug-<generator>/sdl-bgfx-imgui-starter
or ./build/release-<generator>/sdl-bgfx-imgui-starter
.Note: Emscripten is built in a separate build folder called
embuild
, notbuild
. This is to prevent Emscripten from overwriting native builds when built separately.Note: On Windows it may be necessary to run the command-line/terminal as Administrator when building Emscripten.
emcmake
command in the various configure scripts)../configure-emscripten.<bat/sh>
from the root directory.
emsdk_env.bat
or source ./emsdk_env.sh
have been run before attempting this so emcmake
is added to the path (see Emscripten instructions above for more details)../compile-shaders-emscripten.<bat/sh>
located in the root directory. (Note: In order to invoke shaderc
, the third party dependencies (specifically bgfx
) will have to have been built for the target platform as well as Emscripten, so the shaders can be compiled). The build step for Emscripten copies the built shaders to the build folder (embuild
), so compiling the shaders should happen before the main Emscripten build.cmake --build embuild/debug-emscripten
and/or cmake --build embuild/release-emscripten
.python3 -m http.server
).localhost:8000
in a browser and open embuild/<debug/release>-emscripten/sdl-bgfx-imgui-starter.html
.While getting this project setup I discovered a number of excellent resources. I'd highly recommend checking them out to learn more about bgfx
and Dear ImGui
.
bgfx
main repo.bgfx
's API.bgfx
(used by this repo).bgfx
and covers most of the code in the main.cpp
of this repo.bgfx
(showing how to get setup on Ubuntu).premake
and git submodules instead of CMake and with no Dear ImGui
.Dear ImGui
main repo - lots of documentation and examples are available there.imgui
(originally used by this repo but now replaced with a simpler repo called imgui.cmake, similar in design to bgfx.cmake mentioned above).bgfx
CMake supportDear ImGui
CMake supportbgfx
implementation for Dear ImGui
bgfx
setup tutorials.