• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple voxel engine written from the ground up in C++ and OpenGL

Simple Voxel Engine

The code here is the result of a three or four days of free time over the 2016 Christmas break. Both the look and constructible / destructible feel of voxels have always appealed to me perhaps as a result of a childhood playing with Lego and I felt like doing some fun, completely none work related, coding and so I rolled up my sleeves and started coding. Did I have fun? Yup - this was a super fun little project to play with. Since then it's evolved a little and is very much a work in progress.

As this was all about having fun and getting back to basics I stayed away from existing game engines and so other than the STL and some bootstrap OpenGL libraries (glfw, glad and glm) this is all written from the ground up.

At the end of day 3 I had a couple of nice demos of basic rendering that you can see in the "self-portrait" video and screenshots below.

Video of the photo height map demo

(links to YouTube)

Before anyone leans on this code too heavily its worth noting that I haven't written C++ in anger since about 1998 (though I have continued to do a reasonable amount of C) and although I've done some basic 3d work over the years have only used OpenGL in an extremely basic sense. That said if you do want to use it the below may help.

Examples

There are three included examples:

  • bwImageHeightMap - this takes a black and white image, converts it to a height map, and renders it as voxels. You can move around the scene with the keyboard and mouse. Video here.
  • perlinLandscape - generates a height map using perlin noise and creates a simple landscape from it. Perlin noise demo
  • sprites - this demonstrates using voxel sprites and behaviours to build a cityscape. Cityscape demo
  • voxelInvaders - work in progress, a simple space invaders type game that demonstrates sprites, behaviours, and collision detection Invaders demo

Using the engine

Currently this only targets Windows via Visual Studio though the code should be easily portable to other platforms and as my laptop is a Macbook and Parallels doesn't support OpenGL 3.3 I'm likely to port it over to *nix soon.

If your system meets those minimum requirements then open the solution in Visual Studio (I'm currently using the 2017 Community RC) and hit build and you can then run the two examples bwImageHeightMap and perlinLandscape directly from the IDE.

To generate scenes of your own firstly take a look at the examples - they're pretty simple and show the setup process. Following that the key thing to understand is the concept of a chunk factory. Scenes are subdivided into chunks which are grids of voxels (currently 16x16x16 in this engine) and for each chunk in the scene the construct method of the factory will be called and should return a chunk. To do this in code implement a class that derives from the interface IChunkFactory and at least one class that dervies from IVoxel. The reason for the latter is that the engine doesn't make any assumptions about the properties of your voxels and simply asks them to let the engine know what color to use.

Note that chunk creation is executed in parallel and so your code needs to be thread safe.

Future Developments

I'll keep working on this as long as it is fun to do so and I've got a couple of small projects in mind. Some of the engine improvements I have in mind include:

  • Mac / *nix support
  • General optimisation. I've only done the really low hanging fruit so far and there is scope for improvement everywhere. Both OpenGL use and memory management are currently very naive. That said I'm likely to focus on clarity of code and ease of change over raw performance.
  • Voxel sprite support
  • Shadows
  • Skybox / fog support
  • Paging / virtualisation - with this in mind this is one of the main reasons that scenes are constructed using the chunk factory
  • Level of detail support
  • Simple physics

Useful Resources

Coming at the OpenGL world basically from a position of complete ignorance I found the below immensely useful and am massively grateful to the authors.

For a refresher on C++ I basically skim read these:

No doubt I've made lots of mistakes with C++ but after 18 years it mostly felt like putting on a comfy, if slightly itchy, pair of socks!

More Repositories

1

FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
C#
293
star
2

fsharp-wolfenstein

An F# port of the 1992 classic Wolfenstein 3D
F#
161
star
3

AccidentalFish.FSharp.Validation

Simple validator DSL / library for F#
F#
88
star
4

csharp-wolfenstein

CSharp port of Wolfenstein using the funky new language features
C#
70
star
5

WebAPI2AuthenticationExample

Demonstrates how to authenticate using OAuth with Web API 2 and the built in OWIN based OAuth authentication server. The example client is an iOS application written using Xamarin but the C# code will work on any .Net platform.
JavaScript
65
star
6

Simple-Paging-Grid

Lightweight HTML / JavaScript grid designed with Twitter Bootstrap in mind for dynamic server loaded and client embedded data.
JavaScript
56
star
7

AccidentalFish.AspNet.Identity.Azure

Azure table storage based identity provider for ASP.Net 4.5 - swap out for the default Entity Framework implementation
C#
49
star
8

AngularJS-OAuth2

Package for allowing an AngularJS application to authenticate with an OAuth 2 / Open ID Connect identity provider using the implicit flow.
JavaScript
46
star
9

react-azure-adb2c

Looking for a maintainer - if interested please get in touch in issue #13
45
star
10

AzureFromTheTrenches.Commanding

A configuration based commanding and mediator framework that supports command dispatch and execution in-process, over HTTP or over Azure Storage Queues. Written to .NET Standard 2.0 and supports many popular runtimes including .NET Core and .NET 4.6.x.
C#
45
star
11

Pholly

A F# friendly wrapper for Polly providing expressive functional resiience patterns.
Jupyter Notebook
40
star
12

StravaRideAnalysis

A sample application for React and the Strava API designed to illustrate common problems and there solutions
HTML
23
star
13

fsharp-doom

F# version of Doom using original rendering techniques (BSP etc.)
F#
20
star
14

FormSharp

No one likes the drudgery of building form logic. Banish it with F#.
F#
18
star
15

FluentAnimate

Fluent API for UIView animations in Xamarin.iOS
C#
17
star
16

CommandMessagePatternTutorial

Source code to go along with blog posts illustrating the usefulness of the command message pattern in cloud application architecture
C#
17
star
17

WebAPI2MobileFacebookAuthentication

Sample Visual Studio and Xamarin projects demonstrating how to use a Facebook login to authenticate with Web API 2 in a native mobile application.
JavaScript
15
star
18

AccidentalFish.ApplicationSupport

Dependency injectable application framework for Azure applications providing patterns, abstractions and implementations for common activities
C#
14
star
19

AFCircularGestureRecognizer

iOS gesture recognizer that responds to a single finger circular movement
Objective-C
13
star
20

Vsts-GitHub-Pages-Publish

A VSTS build and release task that publishes to GitHub Pages
PowerShell
12
star
21

StravaAPIProxy

A CORS enabled API proxy for Strava that also supports their token exchange process
JavaScript
12
star
22

AngularJS-OAuth2-IdentityServer3-Sample

Sample showing how to use the AngularJS-OAuth2 plugin with IdentityServer3 and Web API
JavaScript
11
star
23

RuntimeFSharpCompilation

Code to accompany blog post
F#
10
star
24

AzureFromTheTrenches.ServerlessBlog

A simple blog implementation for Azure Functions
C#
9
star
25

graphPaper

iPad application for simple vector art and HTML5 / Objective-C code generation
Objective-C
8
star
26

Img2Svg

Converts a bitmap to an SVG file with each pixel represented as a rect
F#
7
star
27

A-Star-Pathfinding

Demonstration of the A* path finding algorithm implemented using JavaScript and HTML canvas.
JavaScript
7
star
28

FSharpTetris

What it says on the tin.
F#
6
star
29

ServerlessLinkShortener

Ridiculously simple serverless (AWS) link shortener
F#
6
star
30

webGLite

A WebGL and TypeScript version of the classic BBC Micro game Elite. A work in progress.
TypeScript
6
star
31

fableTrek

F#
4
star
32

FableElmishScaffold

Visual Studio Code extension for scaffolding of CRUD operations in a F# Fable Elmish style app.
TypeScript
4
star
33

AzureAdOffice365MultiTenantedAuthentication

C#
4
star
34

fsharp-simpleraycaster

A very simple raycast implementation in F#
F#
4
star
35

FunctionMonkey-ToDo-MediatR

The FunctionMonkey ToDo sample using MediatR for the commanding / mediator framework
C#
4
star
36

FunctionMonkeyVideoSeries

Code to go with the video series on Function Monkey, Azure Functions, and the commanding / mediator pattern
C#
4
star
37

Insanely-Simple-Blog

A very simple blog system for embedding in a MVC 4 website using Web API, Backbone and Handlebars
JavaScript
4
star
38

AzureFunctionsSimpleRestApiExample

Simple example of a REST API delivered using Azure Functions
C#
3
star
39

PaddTrekF-

Learning F# with a variant of the classic Star Trek game.
F#
3
star
40

CycleCycleCycle.com

A website for tracking cycling activity
JavaScript
3
star
41

Objective-C-Expression-Tree-Framework

An Objective-C framework suitable for use on the iPhone that implements expression trees, including parsing from strings.
Objective-C
3
star
42

FunctionMonkey-ToDo

Sample back end for a simple Function Monkey ToDo app.
C#
3
star
43

FarmerDbUp

https://www.azurefromthetrenches.com/azure-sql-database-deployment-with-farmer-dbup-and-github-actions/
F#
2
star
44

fableLambdaExample

Demonstrates using F# and Fable to author a API Gateway triggered Lambda and CDK to deploy it
F#
2
star
45

AngularJS-OAuth2-Sample

Sample application for AngularJS-OAuth2
ApacheConf
2
star
46

StravaTokenManager

C# project for managing the Strava token exchange process
C#
2
star
47

AzureLeaseExample

Example of using blob leases
C#
2
star
48

AccidentalFishAngularJSPack

A set of directives and services I find useful to use with AngularJS
JavaScript
2
star
49

fsharp-simpleraycaster-textured

F#
2
star
50

IoCAntipatternFix

Demonstrates a solution to the "every class is public" anti-pattern
C#
2
star
51

6502-Emulator

6502 emulator written in C# as a portable class library
C#
2
star
52

FunctionMonkeyMultiTargettingDemo

Demonstrates how to target both ASP.Net Core and Azure Functions from a single code base.
C#
1
star
53

GpuMandelbrot

A Mandelbrot rendered using a fragment shader on the GPU
JavaScript
1
star
54

HierarchicalToolbar

Hierarchical toolbar for iOS as used in Fluent Mind Map
C#
1
star
55

BasicCommanding

C#
1
star
56

fable-react

Minimal template for Fable and React using Fake and Paket
JavaScript
1
star
57

serverlessJsScalingComparison

Comparisons for scaling
JavaScript
1
star
58

FunctionMonkey-FSharp

Documentation for the F# version of Function Monkey
CSS
1
star
59

PaddTrekJs

JavaScript and HTML version of Padd Trek
JavaScript
1
star
60

AzureLinkboard

Open source bookmark management for Azure
C#
1
star
61

ThreeDSpectreMaze

Small program that uses Spectre.Console to render a maze in the console
C#
1
star
62

fromModularMonolithToMicroservice

C#
1
star
63

The-Game-of-Life

Basic HTML5 and JavaScript implementation of the Game of Life
JavaScript
1
star
64

ServiceBusScheduler

Mediator based command scheduler for the Azure Service Bus
C#
1
star
65

Mandelbrot-Set

A JavaScript, HTML Canvas and Web Worker implementation of the Mandelbrot set.
JavaScript
1
star
66

ServerlessWebNotifier

Simple serverless web page change notifier
F#
1
star
67

FunctionMonkey-ToDo-FSharp

Demonstration of using the FSharp version of Function Monkey
F#
1
star
68

AccidentalFish.ExpressionParser

Simple expression parser for .net (supports .NET Standard 1.3 and higher). Functional but still work in progress.
C#
1
star