Skip to content
jhassePublic

Latest commit

Β 

History

3,439 Commits

Folders and files

Repository files navigation

JNGL - Just a Neat Game Library

🌐 Website πŸƒ Quickstart πŸŽ“ Tutorial πŸ“š Documentation

Chat

An easy to use C++ game library for Linux, Windows, macOS, Android, iOS, Xbox, the Nintendo Switch, LG webOS and the Web.

Portal Dogs running on the Switch

Building from Source

cmake -Bbuild
cmake --build build
./build/jngl-test

Linux

Ubuntu

sudo apt-get install libgl1-mesa-dev libfreetype6-dev libfontconfig1-dev libpng-dev \
libxxf86vm-dev libvorbis-dev cmake g++ libwebp-dev git libsdl3-dev

Fedora

sudo dnf install fontconfig-devel freetype-devel libvorbis-devel libwebp-devel cmake \
ninja-build SDL3-devel gcc-c++ libatomic libavformat-free-devel libswscale-free-devel

The last two are only needed if you plan to use VideoRecorder.

Arch Linux

pacman -Syu --needed cmake gcc sdl3 pkg-config fontconfig libwebp libvorbis

Windows

MSYS2 / MinGW-w64

Set up MSYS2 and install the following in a MinGW-w64 Win64 Shell:

pacman -Syu --needed mingw-w64-x86_64-gcc \
mingw-w64-x86_64-freetype mingw-w64-x86_64-libvorbis mingw-w64-x86_64-libwebp \
mingw-w64-x86_64-dlfcn mingw-w64-x86_64-cmake make mingw-w64-x86_64-gdb \
mingw-w64-x86_64-libtheora mingw-w64-x86_64-SDL3

Visual Studio 2017 or newer

cmake -Bbuild -DFETCHCONTENT_QUIET=0

Then open build/jngl.sln in Visual Studio.

Vulkan

Install the Vulkan SDK, including shaderc, and open a new terminal so that VULKAN_SDK and PATH include it. Enable the Vulkan renderer with the default SDL3 window backend:

cmake -Bbuild-vulkan -DJNGL_VULKAN=1 -DJNGL_WINAPI=OFF
cmake --build build-vulkan --config Release

The same option works with cja: cja build -DJNGL_VULKAN=1.

The built-in shaders are compiled during the build by jngl-shaderc, which needs shaderc_shared.dll from the SDK's Bin directory on PATH. So does the game at runtime, for its jngl::Shaders, unless it's beside the executable. Include this DLL when distributing a Vulkan build. The Vulkan loader is supplied by the graphics driver; users need a Vulkan-capable driver, but do not need the SDK.

Direct3D 12

The Direct3D 12 renderer also needs the Vulkan SDK to build, for its shader compilers (GLSL is compiled to SPIR-V and translated to HLSL by SPIRV-Cross):

cmake -Bbuild-d3d12 -DJNGL_D3D12=1 -DJNGL_WINAPI=OFF
cmake --build build-d3d12 --config Release

During the build, shaderc_shared.dll and spirv-cross-c-shared.dll from the SDK's Bin directory must be on PATH. Unlike Vulkan, it doesn't compile shaders at runtime, so a Direct3D 12 build doesn't need any DLLs of the SDK. Instead, a game's shaders have to be compiled at build time, into a header with a jngl::ShaderBytecode for each jngl::ShaderProgram:

jngl_compile_shaders(${CMAKE_CURRENT_BINARY_DIR}/shaders.hpp shaders
                     blur=data/blur.frag outline=data/outline.vert,data/outline.frag)
add_custom_target(shaders DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/shaders.hpp)
add_dependencies(game shaders)
const jngl::ShaderProgram blur(shaders::blur); // with jngl::Sprite::vertexShader()

Debug builds enable the Direct3D 12 debug layer if the Graphics Tools optional feature of Windows is installed.

macOS

Use Homebrew to install the build dependencies:

brew install sdl3 freetype libvorbis webp pkg-config cmake ffmpeg

ffmpeg is only needed if you plan to use VideoRecorder.

Metal

The experimental Metal renderer needs shaderc to build, for its shader compiler (GLSL is compiled to SPIR-V and translated to the Metal Shading Language by SPIRV-Cross, which is downloaded and built along with JNGL):

brew install shaderc
cmake -Bbuild-metal -DJNGL_METAL=ON
cmake --build build-metal
./build-metal/jngl-test

The same option works with cja: cja build -DJNGL_METAL=1.

Like Direct3D 12, it doesn't compile GLSL at runtime, so a game's shaders have to be compiled at build time with jngl_compile_shaders() (see Direct3D 12 above). The renderer then compiles their MSL with the Metal framework when it creates a jngl::ShaderProgram, so neither building nor running needs Xcode's optional Metal Toolchain, and a Metal build doesn't need shaderc or anything else to be bundled.

To have Metal check how it's used, run a Debug build with MTL_DEBUG_LAYER=1.

Vulkan

Install the Vulkan dependencies, including the MoltenVK driver, which runs on Metal, and select it:

brew install molten-vk vulkan-loader vulkan-headers shaderc vulkan-tools vulkan-validationlayers
export VK_DRIVER_FILES="$(brew --prefix)/etc/vulkan/icd.d/MoltenVK_icd.json"
vulkaninfo --summary
cmake -Bbuild-vulkan -DJNGL_VULKAN=ON
cmake --build build-vulkan
./build-vulkan/jngl-test

To enable Homebrew's validation layer in Debug builds, also set:

export VK_ADD_LAYER_PATH="$(brew --prefix)/share/vulkan/explicit_layer.d"
export DYLD_LIBRARY_PATH="$(brew --prefix vulkan-validationlayers)/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"

Mesa's KosmicKrisp driver (brew install mesa, Apple Silicon with macOS 26 or newer) works too, but it's a lot slower. The LunarG Vulkan SDK can also supply the dependencies; source its setup-env.sh before configuring. JNGL links to the Vulkan loader, so the driver can be selected at runtime. When distributing a Vulkan build, bundle the loader and driver with the application.

Android

  1. Install the Android SDK and set ANDROID_HOME to point to it.
  2. In the Android SDK Manager, install the NDK build tools.
  3. Run the following command to test via ADB:
lus android-run

Alternatively, open android/test in Android Studio and build from there.

Vulkan

The Vulkan renderer works on Android 9 (API level 28) and newer. Build with -DJNGL_VULKAN=ON, e.g. the test app with ./gradlew installDebug -Pvulkan in android/test. The built-in shaders are compiled during the build by jngl-shaderc, which is built for the machine that's building, so it needs a C++ compiler and shaderc there (see Vulkan above for Linux, Windows and macOS). shaderc isn't available on Android, so a game's shaders have to be compiled at build time with jngl_compile_shaders(), like for Direct3D 12 (see above).

iOS

Generate an Xcode project using CMake:

cmake -Bbuild-ios -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/iOS.toolchain.cmake -DIOS_PLATFORM=SIMULATOR

Then open and build build-ios/jngl.xcodeproj in Xcode.

Metal

Instead of OpenGL ES, which iOS has deprecated, the experimental Metal renderer (see macOS above) can be used on iOS and tvOS, too. Building it needs shaderc on the Mac that's building (brew install shaderc), for jngl-shaderc, which is built for the Mac along with the project:

cmake -Bbuild-ios -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/iOS.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DJNGL_METAL=ON

As on macOS, a game's shaders have to be compiled with jngl_compile_shaders().

Example Usage

Here's a simple "Hello, World!" example in JNGL:

#include <jngl.hpp>
#include <jngl/init.hpp>

class MyGame : public jngl::Scene {
    void step() override {
        // game logic
    }
    void draw() const override {
        text.draw(jngl::modelview().translate({ -100, 0 }));
    }
    jngl::Font font{ "Arial.ttf", 12 };
    jngl::TextLine text{ font, "Hello World!" };
};

jngl::AppParameters jnglInit() {
    jngl::AppParameters params;
    params.start = []() {
        return std::make_shared<MyGame>();
    };
    return params;
}

For a more complete starting point (i.e. project structure, etc.) check out the JNGL project template.

Releases

Used by

Contributors

Languages