Menu Share

The BIG2 Stack

by | Published on
category C / C++

For some time I’ve been experimenting with the BGFX library for graphics programming. I even mentioned it in my article about the top engine libraries that you should check out. After I got into it for some time I saw some old and seemingly abandoned repositories called bigg and bigger. I decided that it is time I start my own open-source repository and what better for a first-timer than to do a middleware repository called BIG2 (link).

Table of Contents

Introduction

Well if you’re a newcomer you would probably ask what is BGFX. It is a library that allows you to do graphics programming in such a way that it abstracts the backend. You can then program both your C++ code and your shaders so that they compile on any of platform – even on the proprietary PlayStation. This is quite important for a game developer that wants to focus on his game instead of constantly being stuck in the “developing my own engine” hell. BGFX also gives you the ability to write Vulkan without having to write a 1000 lines of code for a triangle.

Anyway this stack will be useful for any graphics programmer since it doesn’t focus only on games. You will see in my explanation that you can develop regular UI applications using the ImGui library. This is similar to an youtube video by The Cherno where he explains how to make tools in ImGui – Part 1 and Part 2.

The Stack

The BIG2 stack that is presented here is not my original idea but the implementation is 100% new and using modern CMake. The elements of this stack are:

  • BGFX
  • ImGui
  • GLFW
  • GLM

Hence the name BIGG or BIG2 .

BGFX

This is at the core of the stack and the stack cannot work without the BGFX library. This library is split into a few repositories and is not initially set up using CMake. It does have a CMake repository as of today that is officially supported. It combines three sublibraries called BX, BIMG & BGFX. The library also contains a few tools for shader compilation, texture compilation, etc.

About shaders it is important to note that BGFX has its own shading language that is derived from GLSL. It then uses its own compiler called shaderc to compile those source shaders into shaders for multiple platforms by using the spirv-cross libraries. In my stack I also introduce a helper cmake function for compiling the shaders:

add_shaders_directory("${CMAKE_CURRENT_SOURCE_DIR}/shaders" SHADERS_TARGET_NAME)

add_executable(MyExe src/main.cpp)
target_link_libraries(MyExe PUBLIC "${SHADERS_TARGET_NAME}")

This way inside a directory called shaders you can write your BGFX shaders like this:

  • myexe
    • shaders
      • vs_basic.sc
      • fs_basic.sc
      • varying.def.sc

This will setup and generate shader files inside your build directory in such a way that you can then include them using #include <generated/shaders/myexe/all.h> which is quite convenient.

ImGui

If you’re not already familiar ImGui it is a library that allows you to specify your graphics state for each frame and then it will pass it to a rendering engine for drawing.

In my stack I’ve made ImGui conditional. It will be enabled by default but if you want just a quick stable setup of BGFX along with GLFW and GLM you can exclude imgui. Otherwise I also added four custom functions for easy integration of imgui with your project and a precompiler definition called BIG2_IMGUI_ENABLED. You can check out the example functions and their usage in the following file.

GLM

GLM is just a math library. It is very useful for graphics programming and allows you to use many utility functions. This is also made optional in my stack since you might only care about the UI part of the programming. If so just disable it with the coresponding cmake option.

GLFW

This is just a library that allows for window creation. I find it better than alternative options since it is very lightweight. It is not optional in this stack but otherwise you can find the example usage of GLFW in the basic example.

How to use the BIG2 stack?

To use it you either clone it inside your cmake project and then use add_subdirectory(big2-stack) or you could use the FetchContent syntax of CMake:

include(FetchContent)

fetchcontent_declare(
        big2
        GIT_REPOSITORY "https://github.com/Paper-Cranes-Ltd/big2-stack.git"
        GIT_TAG "v0.0.1"
        GIT_SHALLOW TRUE
)

fetchcontent_makeavailable(big2)

Conclusion

I explained my stack and the utilities that I’ve added for now. It is the very barebones version but I will be adding more with time. If you want to know more about graphics programming with BGFX then you could subscribe for notifications. I will be adding more content on the topic with more in-depth examples.

Leave a comment

Your email address will not be published. Required fields are marked *