Project: GPU-Accelerated Minecraft Clone Language: C++23 Graphics API: OpenGL 4.3+ (Compute Shaders) Build Systems: Premake5 (Windows), CMake (Linux/WSL)
# Clone with submodules
git clone --recursive https://github.com/suparious/minecraft.cpp.git
cd minecraft.cpp
# Generate VS solution
./GenerateProjects.bat
# Open VoxelEngine.sln in Visual Studio, build (F7), run# Clone with submodules
git clone --recursive https://github.com/suparious/minecraft.cpp.git
cd minecraft.cpp
# Install dependencies (Ubuntu/Debian)
sudo apt install build-essential cmake libglfw3-dev libgl1-mesa-dev libx11-dev libxrandr-dev libxi-dev libxxf86vm-dev
# Build (use .build/ directory - hidden, not build/)
mkdir -p .build/linux && cd .build/linux
cmake ../..
make -j$(nproc)
# Run from the bin directory (assets are copied there)
cd bin && ./MinecraftClone# Install MinGW cross-compiler
sudo apt install mingw-w64
# Configure and build (use .build/ directory - hidden, not build-windows/)
mkdir -p .build/windows && cd .build/windows
cmake ../.. \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
-DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres \
-DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
# Output: bin/MinecraftClone.exe (run from Windows with bin/assets/)# Build both Windows and Linux, package into releases/
./release.sh v1.2.0
# Output:
# releases/minecraft.cpp-v1.2.0-windows.zip
# releases/minecraft.cpp-v1.2.0-linux.tar.gzVoxelEngine/
├── VoxelEngine/ # Engine core (static library)
│ ├── src/
│ │ ├── pch.h/cpp # Precompiled headers
│ │ ├── VoxelEngine.h # Public API
│ │ ├── Platform/ # Window/Input (GLFW-based, cross-platform)
│ │ └── VoxelEngine/
│ │ ├── Core/ # Application, layers, events
│ │ ├── Events/ # Event system
│ │ ├── Renderer/ # OpenGL rendering, shaders, textures
│ │ ├── ImGui/ # Debug UI
│ │ └── Debug/ # Profiling (GpuProfiler)
│ └── vendor/ # Dependencies (git submodules)
│ ├── GLFW/ # Window/input
│ ├── GLAD/ # OpenGL loader
│ ├── glm/ # Math library
│ ├── imgui/ # UI
│ ├── spdlog/ # Logging
│ ├── stb_image/ # Image loading
│ ├── tracy/ # Profiler
│ └── raudio/ # Audio
│
├── MinecraftClone/ # Application layer
│ ├── src/
│ │ ├── MinecraftCloneApp.cpp # Entry point
│ │ ├── Layers/
│ │ │ ├── GameLayer.h/cpp # Main game logic
│ │ │ └── GameConfig.h # World configuration
│ │ └── Overlays/
│ │ └── DebugOverlay.h/cpp
│ └── assets/
│ ├── shaders/ # GLSL shaders
│ │ ├── compute/ # GPU compute shaders (8 files)
│ │ ├── drawTerrain.glsl
│ │ └── tntInstancing.glsl
│ ├── textures/ # Block textures (16x16 PNG)
│ └── audio/ # Sound effects (OGG)
│
├── doc/ # Documentation
│ └── ROADMAP.md # Development roadmap
├── premake5.lua # Windows build config
├── CMakeLists.txt # Linux/WSL build config
├── release.sh # Build script for releases
└── CLAUDE.md # This file
- Layer System: Game logic in layers (GameLayer), UI in overlays (DebugOverlay)
- Event System: Keyboard, mouse, window events dispatched through layers
- Renderer: OpenGL 4.3+ with compute shaders for GPU parallelism
World Generation:
generateBlocks.glsl → Block types per chunk (terrain)
generateQuads.glsl → Mesh generation (greedy meshing)
TNT Physics:
initTntData.glsl → Initialize TNT state
activateTnt.glsl → Raycast activation
explodeTnts.glsl → Physics update (velocity, gravity)
propagateExplosions.glsl → BFS explosion propagation
updateTntTransforms.glsl → Position updates
clearExplosions.glsl → Reset tracking
Application- Main loop, layer managementWindow- GLFW window wrapperShader/ShaderLibrary- GLSL compilation and managementBuffer/StorageBuffer- GPU data (VBO, SSBO)GameLayer- Main game logic, chunk management, renderingGpuProfiler- OpenGL timer query-based GPU profiling (singleton)DebugOverlay- ImGui-based debug UI with profiler display
Edit MinecraftClone/src/Layers/GameConfig.h:
// World size (chunks)
constexpr int WORLD_WIDTH = 35; // X/Z dimension
constexpr int WORLD_HEIGHT = 20; // Y dimension
// Block/chunk constants
constexpr int CHUNK_SIDE_LENGTH = 16;
constexpr int SURFACE_LEVEL = 100;
// TNT demo
constexpr int HOW_MANY_TNT_TO_SPAWN = 10'000'000;Performance Tips:
- Lower
WORLD_WIDTHto 25 if GPU memory limited - Lower
HOW_MANY_TNT_TO_SPAWNto 100,000 for testing
- Block rendering with texture atlas
- Perlin noise terrain generation (hills/valleys with grass/dirt/stone/bedrock)
- Block placement and breaking (raycast selection, hotbar)
- TNT explosion physics (10M entities)
- First-person camera movement (WASD + mouse)
- Ambient occlusion (per-vertex AO)
- Distance fog (150-400 block fade)
- Basic audio (explosions, fuse)
- Debug overlay (ImGui, Windows only)
- GPU profiler (F3 toggle, timer queries for all compute/draw operations)
- Inventory/crafting
- Mobs/entities (except TNT)
- Caves, biomes, trees
- Lighting/shadows
- Day/night cycle
- World saving/loading
- Menus
- Add enum value in
globalInclude.glsl(shared shader constants) - Add texture to
assets/textures/texture_pack/ - Update texture atlas generation in
GameLayer.cpp - Add texture ID mapping in
globalInclude.glsl
- Create
.glslfile inassets/shaders/compute/ - Load shader in
GameLayer::OnAttach()usingShaderLibrary - Dispatch with
glDispatchCompute()and proper barriers
- Edit
assets/shaders/compute/generateBlocks.glsl - Uses 256 threads per chunk (16x16 local workgroup), one thread per X-Z column
- Each thread generates all Y blocks in its column
- Output to chunk SSBO (Storage Buffer)
The Platform/Windows/ code is actually cross-platform GLFW despite the name.
For true platform-specific code, use:
#ifdef VE_PLATFORM_WINDOWS
// Windows-specific
#elif defined(VE_PLATFORM_LINUX)
// Linux-specific
#endif| Config | Use Case | Defines |
|---|---|---|
| Debug | Development, OpenGL error logging | VE_DEBUG |
| Release | Testing with optimizations | VE_RELEASE |
| Dist | Distribution, no debug overhead | VE_DIST |
| Library | Purpose | Notes |
|---|---|---|
| GLFW | Windowing/input | Cross-platform |
| GLAD | OpenGL loader | Generated for 4.3 core |
| GLM | Math (vec3, mat4) | Header-only |
| ImGui | Debug UI | Docking branch |
| spdlog | Logging | Header-only |
| stb_image | PNG loading | Single header |
| Tracy | Profiling | Optional |
| raudio | Audio playback | From raylib |
If submodules are missing:
git submodule update --init --recursiveRun in Debug configuration - errors logged to console via spdlog.
Press F3 to toggle the debug overlay with GPU profiler. Uses OpenGL timer queries to measure actual GPU time:
How it works:
GpuProfiler::Get().BeginQuery("name")/EndQuery("name")wrap GPU operations- Reads previous frame's results to avoid pipeline stalls
- Exponential moving average for smooth display
- Color-coded: green (<5ms), yellow (5-10ms), red (>10ms)
Profiled operations:
| Query Name | Location | Description |
|---|---|---|
| explodeTnts | GameLayer.cpp | TNT fuse timer compute shader |
| propagateExplosions | GameLayer.cpp | Explosion BFS (8 iterations) |
| updateTntTransforms | GameLayer.cpp | TNT physics/velocity compute |
| clearExplosions | GameLayer.cpp | Reset explosion tracking |
| generateQuads | GameLayer.cpp | Mesh regeneration compute |
| selectBlock | GameLayer.cpp | Raycast block selection |
| drawTerrain | GameLayer.cpp | Multi-draw indirect terrain |
| drawTnt | GameLayer.cpp | TNT instanced rendering |
Adding new profiling points:
#include <VoxelEngine/Debug/GpuProfiler.h>
// Option 1: Manual begin/end
GpuProfiler::Get().BeginQuery("myOperation");
glDispatchCompute(...);
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GpuProfiler::Get().EndQuery("myOperation");
// Option 2: RAII scope (auto end on scope exit)
{
VE_GPU_PROFILE_SCOPE("myOperation");
glDispatchCompute(...);
}Tracy profiler integrated. Look for VE_PROFILE_FUNCTION and VE_PROFILE_SCOPE macros.
- Black screen: Check shader compilation errors in console
- Crash on startup: Lower
WORLD_WIDTHorHOW_MANY_TNT_TO_SPAWN - Missing textures: Verify
assets/folder is in working directory
See doc/ROADMAP.md for the complete development plan.
Already Implemented:
- Block interaction (breaking/placing, raycast, hotbar)
- Heightmap terrain (Perlin noise hills/valleys)
- Ambient occlusion (per-vertex AO)
- Distance fog (150-400 block fade)
Phases:
- Phase 1: Foundation (inventory, player physics) - partially done
- Phase 2: World (caves, ores, biomes, trees)
- Phase 3: Gameplay (crafting, tools, survival)
- Phase 4: Entities (mobs, items)
- Phase 5: Environment (lighting, day/night, water)
- Phase 6: Polish (menus, saving, audio)
- Fork the repository
- Create feature branch
- Follow existing code style (
.clang-formatprovided) - Test on both Windows and Linux if possible
- Submit PR with description
CRITICAL WARNINGS - READ BEFORE MAKING CHANGES:
-
GLSL Version Compatibility (RESOLVED): We now use GLSL 4.50 +
GL_ARB_shader_draw_parametersextension with a#define gl_BaseInstance gl_BaseInstanceARBfor broad driver compatibility. This was the correct fix for Mesa/WSL2 support. -
Do NOT modify code to work around build errors. If cross-compilation fails (e.g., Tracy with MinGW), tell the user to build natively instead of hacking the codebase.
-
Always verify claims before stating them. When asked "what's the impact of X?", actually grep/search the code for affected features. Don't guess.
-
WSL GPU Support: Mesa's llvmpipe is software rendering. For real GPU:
export GALLIUM_DRIVER=d3d12 # Required for AMD/Intel GPUs in WSL
-
Shader Compatibility Fix:
drawTerrain.glsluses GLSL 4.50 with ARB extension for broad Mesa compatibility:#version 450 core #extension GL_ARB_shader_draw_parameters : require #define gl_BaseInstance gl_BaseInstanceARB
Note: GLSL 4.60 provides
gl_BaseInstancedirectly. GLSL 4.50 + extension providesgl_BaseInstanceARB. -
Tracy Profiler: Disabled by default. pch.h has a guard to default TRACY_ENABLE=0. When building with
-DTRACY_ENABLE=ON, the guard is bypassed. Tracy ETW code does NOT compile with MinGW. -
Build Systems:
- Windows native: Use Premake5 + Visual Studio (GenerateProjects.bat) - user must run from Windows terminal.
- Linux/WSL native: Use CMake with
.build/linux/directory. - Cross-compile Windows from WSL: Use CMake with MinGW in
.build/windows/directory. - Release builds: Use
./release.sh vX.Y.Z- builds both platforms and packages toreleases/. - IMPORTANT: NEVER create
build/orbuild-windows/directories in the project root. Always use.build/(hidden) or the release script.
-
NEVER invoke Windows executables from WSL. Do NOT use
cmd.exe,powershell.exe, orGenerateProjects.batfrom WSL. This is stupid and doesn't work. Use CMake cross-compilation with MinGW instead, or tell the user to run Windows commands from a Windows terminal themselves. -
Current State (Dec 2025):
- Repository: https://github.com/suparious/minecraft.cpp
- Latest release: v1.2.0 (performance optimizations, cross-platform fixes)
- Submodules point to official upstream repos (glfw/glfw, ocornut/imgui docking branch, etc.)
- Premake build files in
VoxelEngine/vendor-build/for Windows builds - MinGW cross-compile uses
-staticlinking to avoid DLL dependencies - GPU profiler added:
GpuProfiler.hsingleton with timer queries, visible via F3 debug overlay
-
WSL2 AMD Driver Bug: The D3D12 OpenGL translation on WSL2 with AMD GPUs crashes in
amdxc64.so(AMD shader compiler). This is a driver bug, not fixable in code. Workarounds:- Use software rendering (llvmpipe) - slow but works
- Build natively on Windows instead of WSL2
- ImGui is disabled on Linux to avoid related crashes
-
ImGui Compatibility: The docking branch (Dec 2025) has
ImGuiBackendFlags_RendererHasTexturesfor dynamic font atlas. This crashes on WSL2's D3D12 layer. ImGui layer is conditionally disabled on Linux inApplication.cpp. -
Release Workflow: Use
./release.sh v1.x.xto build both Windows and Linux packages. Creates zip/tarball inreleases/directory. Then usegh release createto publish to GitHub.
Trust but verify. Don't make changes you can't justify with evidence from the codebase.
Last Updated: December 19, 2025 (GPU profiler added, keybinds updated)
This repo is part of the SolidRusT Networks ecosystem managed by srt-concierge.
For cross-repo context, service dependencies, and platform strategy:
- Repo inventory:
/Users/shaun/repos/srt-concierge/docs/REPOSITORY-METADATA.md - Service map:
/Users/shaun/repos/srt-concierge/docs/PRODUCTION-SERVICES.md - Network topology:
/Users/shaun/repos/srt-concierge/docs/NETWORK-TOPOLOGY.md - Team registry:
/Users/shaun/repos/srt-concierge/docs/TEAM-REGISTRY.md