Demo & Introduction
Minecraft is my favourite childhood game, and my love for it remains the same today. So I set out to build my own version of it from scratch, without any assistance of a modern 3D game engine.
I developed it purely using C++ and OpenGL, which is how Minecraft was made except the game was written in Java. So this project was partly an attempt to understand what goes on underneath a game I have spent so much time playing.
Without any mesh optimization, my first working version ran at just 10 FPS. The finished engine holds 120 FPS at a 16 × 16 chunk render distance. Almost all of the optimization work came from figuring out what the engine does not need to draw.
Features
Below are features I implemented in my voxel engine:
- Chunked terrain: Divided the world into chunks so terrain could be generated and rendered independently.
- Procedural world generation: Generated terrain from a Perlin noise height map for smooth, natural terrain, using space partitioning so only the chunks inside the render distance were drawn.
- Mesh optimization: Implemented two optimizations that accounted for most of the frame rate improvement: culling interior faces at mesh build time, and back-face culling on the GPU.
- Texture atlasing: Packed all *256 block textures into a single image, allowing the engine to bind one texture instead of hundreds.
- DDA raycasting: Implemented to find the block the player was pointing at, which formed the basis for block placing and breaking.
- Swept AABB collision detection: Implemented to prevent the player from falling through the world, even at low frame rates.
- 3D positional audio: Added positional audio with different sound effects depending on the block type.
The Hard Part
There was no written solution for implementing all of these features in a Minecraft-like game. I had to read through online posts, discussions, and documentation to figure out how other people approached these problems, and then come up with my own solutions that worked for my engine.
How it works
I further documented technical challenges I faced and solutions I came up with along the way. So if you're curious, click on a chapter and have a look!
Stack
- C++
- OpenGL
- OpenAL
- GLM