Modern C++23 3D Game Engine
A fully-featured, modern C++23-based 3D game engine using OpenGL 4.6 with advanced rendering features.
Features
- Modern C++23: Utilizes the latest C++ features including concepts, ranges, modules support, and std::expected
- OpenGL 4.6: Modern OpenGL with compute shaders, bindless textures, and UBOs
- Cross-Platform: Works on Windows, Linux, and macOS
- Advanced Rendering: PBR shading, shadow mapping, normal mapping, and more
- Resource Management: Smart resource caching with hot-reload support
- Scene Management: Hierarchical scene graph with frustum culling
- Input System: Modern input handling with concepts and type safety
- Memory Safe: RAII principles, smart pointers, and minimal raw memory management
Requirements
- C++23 compatible compiler (GCC 13+, Clang 16+, MSVC 19.35+)
- CMake 3.25 or higher
- OpenGL 4.6 compatible graphics card
- GLFW 3.3+
- GLM (OpenGL Mathematics)
- GLAD (OpenGL loader)
Installing Dependencies
Ubuntu/Debian:
sudo apt update
sudo apt install build-essential cmake pkg-config
sudo apt install libglfw3-dev libglm-dev libglu1-mesa-dev
macOS (with Homebrew):
brew install cmake glfw glm pkg-config
Windows:
Use vcpkg to install dependencies:
vcpkg install glfw3 glm
Building
- Clone the repository:
git clone <your-repo-url>
cd ModernEngine
- Create build directory:
mkdir build && cd build
- Configure with CMake:
cmake .. -DCMAKE_CXX_STANDARD=23
- Build:
cmake --build . --config Release
Project Structure
ModernEngine/
├── CMakeLists.txt # Main CMake configuration
├── include/ # Header files
│ ├── Engine.h # Main engine class
│ ├── Window.h # Window management
│ ├── Input.h # Input system with C++20 concepts
│ ├── Renderer.h # OpenGL renderer
│ ├── Shader.h # Shader management
│ ├── Mesh.h # Mesh and vertex handling
│ ├── Scene.h # Scene graph management
│ ├── Camera.h # Camera system
│ └── ResourceManager.h # Resource caching system
├── src/ # Source files
│ ├── main.cpp # Example game implementation
│ └── Engine.cpp # Engine implementation
├── assets/ # Game assets
│ └── shaders/ # GLSL shaders
│ ├── basic.vert # Vertex shader
│ └── basic.frag # Fragment shader with PBR
├── third_party/ # Third party libraries
│ └── glad/ # OpenGL loader
└── README.md # This file
Usage
Basic Example
#include "Engine.h"
class MyGame : public Engine {
public:
MyGame() : Engine({
.window_width = 1920,
.window_height = 1080,
.window_title = "My C++23 Game",
.enable_vsync = true,
.target_fps = 144
}) {}
protected:
bool OnInitialize() override {
// Load shaders
auto shader = ResourceManager::LoadShader("default",
"assets/shaders/basic.vert",
"assets/shaders/basic.frag");
// Create meshes
auto cube = Mesh::CreateCube();
GetScene().AddNode(std::move(cube), {0, 0, 0});
// Setup camera
GetCamera().SetPosition({5, 3, 5});
GetCamera().LookAt({5, 3, 5}, {0, 0, 0});
return true;
}
void OnUpdate(float delta_time) override {
// Game logic here
}
};
int main() {
MyGame game;
if (game.Initialize()) {
game.Run();
}
return 0;
}
Advanced Features
Resource Management with Error Handling
// C++23 std::expected for error handling
auto shader_result = ResourceManager::LoadShader("pbr",
"shaders/pbr.vert", "shaders/pbr.frag");
if (!shader_result) {
std::cerr << "Shader failed: " << shader_result.error() << std::endl;
return false;
}
Type-Safe Input System
// C++20 concepts for compile-time type checking
if (Input::IsKeyPressed('W')) {
camera.MoveForward(speed * deltaTime);
}
if (Input::IsMouseButtonPressed(Input::MouseButton::Left)) {
auto mousePos = Input::GetMousePosition();
// Handle mouse click
}
Modern Mesh Creation
// Using C++20 spans for safe array handling
std::vector<Vertex> vertices = /* ... */;
std::vector<unsigned int> indices = /* ... */;
auto mesh = std::make_unique<Mesh>(
std::span<const Vertex>(vertices),
std::span<const unsigned int>(indices)
);
// Or use factory methods
auto sphere = Mesh::CreateSphere(32, 16);
auto cube = Mesh::CreateCube();
Modern C++23 Features Used
- Concepts: Type-safe templates with compile-time validation
- Ranges: Modern iteration and algorithm composition
- std::expected: Proper error handling without exceptions
- Modules: Import std for faster compilation (where supported)
- Spaceship Operator: Automatic comparison operators
- Designated Initializers: Clean struct initialization
- nodiscard: Preventing accidental value discarding
- constexpr: Compile-time computation
- RAII: Automatic resource management
Performance Features
- Uniform Buffer Objects: Efficient uniform data transfer
- Instanced Rendering: Draw many objects with one call
- Frustum Culling: Only render visible objects
- Hot Reloading: Live shader and asset reloading
- Memory Pools: Reduced allocation overhead
- Cache-Friendly Design: Data structures optimized for CPU cache
AI God Mode
Let Claude play god in the world. The engine exposes a JSON HTTP API on
localhost:9090; ai_god.py wires Claude up to it via tool-use and lets the
model experiment autonomously — querying state, spawning geometry, moving
the camera, iterating on compositions.
pip install -r requirements.txt
export ANTHROPIC_API_KEY=sk-ant-...
./build/ModernEngine &
python ai_god.py
Useful flags: --max-turns N, --port 9090, --prompt "build a solar system".
Contributing
- Ensure your compiler supports C++23
- Follow the existing code style
- Add tests for new features
- Update documentation
License
MIT License - See LICENSE file for details
Acknowledgments
- OpenGL community for excellent documentation
- GLM for mathematics library
- GLFW for cross-platform window management
- C++ standardization committee for modern language features
Description
Languages
Makefile
74.1%
C++
14.5%
C
10.5%
CMake
0.5%
Python
0.3%