
OpenGL Voxel Engine C++
Engine: OpenGL
Project Type: Personal
Whilst my undergraduate course course taught me a lot, it didn't teach me any graphics programming. To teach myself this, I created this custom 3D voxel engine just after my undergraduate final deadlines. I made this using OpenGL (and by looking at a lot of documentation). The primary goal was to create a system to render large procedurally generated worlds whilst addressing performance issues such as draw calls, unnecessary rendering and memory usage.
​
Key Features:
-
A Camera System
-
Dynamic chunk generation for infinate worlds
-
Face Culling​
-
Procedural Generation
​
Potential Future Features:
-
Multithreading for smooth terrain generation
-
Frustum culling
Technical Breakdown
Optimisation
As millions of blocks will be created, I need to think about what data is neccessary to be stored in the block class. If unnecessary data is stored here, it will cause a higher memory usage. For this reason, my block class is as minimal as possible


Another optimisation is to split the map into chunks to reduce draw calls to the GPU. The bigger the chunk, the less draw calls. However, you have less control over view distance and if you break or place a block in that chunk the mesh needs to be generated again for the whole chunk. For a large chunk this could take a while. For this reason, I chose to make my chunks 16x16 as this is a good middle ground.
Shaders and Lighting
Vertex Shader
The vertex shader is simple, its only job is transform 3D vertices into pixels onto a 2D screen. These positions then get sent to the fragment shader to have lighting and colour added.
Fragment shader (Lighting)
A fragment shader (also known as a pixel shader) in my usage controls the colour and lighting. This project uses the phong lighting model, meaning it has ambient, diffused and specular lighting combined to make a lit scene. This is nice as it's not complicated and ends up with a good, realistic outcome. It can also easily be changed to suit different games needs.
Shader Class
To easier manage shader files, I built a shader class which reads shaders from the disk, compiles, and links them. This is extremely useful as it's a lot easier to use than having to manage the shaders myself. This code was mainly found online, but I have used it and implemented it into my project myself.






