A minimal CMake-based template for integrating raylib (using its low-level rlgl abstraction) with cimgui (C bindings for Dear ImGui) in pure C. This project demonstrates a standalone setup for rendering a rotating 3D cube with an ImGui overlay for interactive controls, without relying on the full raylib high-level API. It's ideal for prototyping tools, games, or apps where you want direct control over OpenGL via rlgl, GLFW for windowing, and raymath for vector/matrix math, all while adding an immediate-mode GUI.This template is inspired by official raylib examples and cimgui backends, adapted for a lightweight, header-only workflow. It supports Windows, Linux, and macOS out-of-the-box via CMake, with static linking options for portability.Features
- Pure C Implementation: No C++ required—uses cimgui for ImGui bindings.
- Low-Level Rendering: Leverages rlgl.h for OpenGL 3.3 core profile rendering (e.g., perspective projection, depth testing, matrix transformations).
- 3D Example: Renders a colorful rotating cube using raymath for matrices and camera setup.
- ImGui Integration: Overlay with text, sliders (e.g., control cube rotation), and demo windows. Uses GLFW and OpenGL3 backends.
- Dynamic Resizing: Handles window resizing with viewport updates.
- Cross-Platform: Builds with CMake; tested on Windows (MinGW/MSVC), Linux (GCC/Clang), macOS.
- Minimal Dependencies: Fetches raylib and cimgui via FetchContent; links GLFW and OpenGL automatically.
- Static Linking: Optional full static build on Windows for standalone executables.
-
CMake 3.15 or later.
-
A C compiler (GCC, Clang, MSVC).
-
Git (for cloning submodules if building manually).
-
OpenGL development headers (usually provided by your system or via package manager, e.g., libgl1-mesa-dev on Ubuntu).
No need to pre-install raylib or cimgui—CMake handles fetching them.Building with CMake.
- Ubuntu/Debian: sudo apt install libglfw3-dev libgl1-mesa-dev
- macOS (with Homebrew): brew install glfw glew
- Windows: Use vcpkg or ensure MinGW includes them.
- Run the executable: A window opens showing a yellow background with a rotating multicolored 3D cube (viewed from a perspective camera at (5,5,5)).
- ImGui Window: Drag the "Cube Y Rotation" slider to interactively control the cube's rotation (overrides auto-rotation). Text displays the current value.
- Controls:
- Mouse: Drag ImGui elements.
- Keyboard: ESC to close.
- Resize: Window adapts automatically.
- Auto-Rotation: The cube spins at 30°/second around the Y-axis unless the slider is active.
The main loop follows the standard ImGui + custom OpenGL flow:
- Poll events.
- Clear buffers (color + depth).
- Start ImGui frame.
- Build UI.
- Set projection/view/model matrices.
- Draw cube via rlBegin(RL_TRIANGLES).
- Flush batch with rlDrawRenderBatchActive().
- Render ImGui.
- Swap buffers.
raylib_cimgui/
├── CMakeLists.txt # CMake configuration (fetches raylib/cimgui, builds static cimgui lib)
├── src/
│ └── main.c # Entry point: GLFW setup, rlgl init, ImGui integration, cube rendering
└── README.md # This file
- Standalone rlgl: Avoids full raylib overhead; rlgl.h provides OpenGL emulation (fixed-function style in core profile).
- cimgui for C: Dear ImGui is C++-native, but cimgui generates pure C bindings—perfect for raylib's C ecosystem.
- Learning Curve: It took time to reconcile rlgl matrices with ImGui's state (e.g., reset glUseProgram(0) before ImGui render). Few pure-C examples exist, so this template fills the gap.
- Performance Note: cimgui adds minor overhead vs. native C++ ImGui, but it's negligible for tools/prototypes. For high-perf, consider rlImGui (C++ wrapper).
- raylib: Core library and rlgl_standalone.c example for low-level OpenGL setup. https://github.com/raysan5/raylib
- cimgui: C bindings for Dear ImGui, with GLFW+OpenGL3 backend example. https://github.com/cimgui/cimgui
- WEREMSOFT/c99-raylib-cimgui-template: Influenced the C99 integration and CMake structure for raylib + cimgui. https://github.com/WEREMSOFT/c99-raylib-cimgui-template
- raylib-cimgui: Additional reference for pure-C ImGui backends. https://github.com/alfredbaudisch/raylib-cimgui
- Community: raylib Discord/Reddit for troubleshooting matrix issues and state resets.
- It took a while to learn how raylib and cimgui. Had to search around which there are few projects work on cimgui.