pr0g / sdl-bgfx-imgui-starter

A starter project for graphics applications using SDL, bgfx and Dear ImGui
MIT License
312 stars 33 forks source link

sdl-bgfx-imgui-starter

starter

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.

Prerequisites

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.

Build Instructions

All

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 a configure-vs-19/22.bat for generating a Visual Studio 2019 or 2022 solution.

Windows

macOS

Linux

Emscripten (Windows/macOS/Linux)

Note: Emscripten is built in a separate build folder called embuild, not build. 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.

Resources

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.

Special Thanks