Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10)

project(
SimpleVoxelEngine
VERSION 1.0
LANGUAGES CXX)

add_subdirectory(depends)
add_subdirectory(voxelEngine)
add_subdirectory(examples)


11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ For a refresher on C++ I basically skim read these:
* [Effective Modern C++](https://www.amazon.co.uk/gp/product/1491903996)

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!

## Linux
To build in Linux:

```
$ sudo apt-get install glew-utils libglew-dev libglm-dev libglfw3-dev
$ mv depends/src/glad/glad.c depends/src/glad/glad.cpp
$ mv depends/include/glm depends/include/_glm
$ mkdir build ; cd build
$ make -j 8
```
7 changes: 7 additions & 0 deletions depends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.10)

add_library(glad src/glad/glad.cpp)

target_include_directories(glad PRIVATE include/)


67 changes: 0 additions & 67 deletions depends/include/glm/CMakeLists.txt

This file was deleted.

7 changes: 7 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.10)
add_subdirectory(bwImageHeightMap)
add_subdirectory(perlinLandscape)
add_subdirectory(sprites)
add_subdirectory(voxelInvaders)


15 changes: 15 additions & 0 deletions examples/bwImageHeightMap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)

project(
bwImageHeightMap
VERSION 1.0
LANGUAGES CXX)

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
list(APPEND SRC_FILES)
add_executable(bwImageHeightMap ${SRC_FILES})
target_link_libraries(bwImageHeightMap voxelengine glad -lX11 -lglfw -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama)

target_include_directories(bwImageHeightMap PRIVATE ../../voxelEngine/include/ ../../depends/include/ ../../depends/include/glad/ src/)


2 changes: 2 additions & 0 deletions examples/bwImageHeightMap/ImageSourceChunkFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "IChunkManager.h"
#include "GreyScaleVoxel.h"

#include <string>


ImageSourceChunkFactory::ImageSourceChunkFactory(std::string sourceImageFilename, bool inverseHeight, bool inverseColor, bool isBlackAndWhite) : _image(sourceImageFilename.c_str()), _inverseHeight(inverseHeight), _inverseColor(inverseColor), _isBlackAndWhite(isBlackAndWhite)
{
Expand Down
8 changes: 4 additions & 4 deletions examples/bwImageHeightMap/bwImageHeightMap.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <glad/glad.h>
#include "glad/glad.h"
#include <glfw/glfw3.h>
#include "VoxelEngine.h"
#include "ImageSourceChunkFactory.h"
Expand All @@ -14,14 +14,14 @@ static void error_callback(int error, const char* description);
int main(int argc, char** argv) {
std::string programPath(argv[0]);
size_t lastSlash = programPath.find_last_of('\\');
std::string shaderPath = programPath.substr(0, lastSlash) + "\\shaders\\";
std::string shaderPath = "shaders/";

GLFWwindow* window;
if (setupEnvironment(window)) return -1;

// Configure the voxel engine to display voxels based on a perlin noise algorithm and connect the camera to the mouse and keyboard
//std::shared_ptr<ImageSourceChunkFactory> chunkFactory = std::make_shared<ImageSourceChunkFactory>(".\\sourceImageVerySmall.bmp", false, false);
std::shared_ptr<ImageSourceChunkFactory> chunkFactory = std::make_shared<ImageSourceChunkFactory>(".\\sourceImageVerySmall.bmp", false, false);
//std::shared_ptr<ImageSourceChunkFactory> chunkFactory = std::make_shared<ImageSourceChunkFactory>("sourceImageVerySmall.bmp", false, false);
std::shared_ptr<ImageSourceChunkFactory> chunkFactory = std::make_shared<ImageSourceChunkFactory>("sourceImageVerySmall.bmp", false, false);
worldSize worldDimensions(chunkFactory->requiredWidth(), 3 * IChunk::Height, chunkFactory->requiredDepth());
std::shared_ptr<ICameraControllerInput> cameraInputController = std::make_shared<MouseAndKeyboardCameraControllerInput>(window, 0.005f, 64.0f);
std::shared_ptr<ILightSource> light = std::make_shared<SimpleLight>(lightSourcePosition(50.0f, 400.0f, 50.0f), color(1.0f, 1.0f, 1.0f), 128000.0f);
Expand Down
4 changes: 2 additions & 2 deletions examples/bwImageHeightMap/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#pragma once

#include "targetver.h"
//#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
//#include <tchar.h>



Expand Down
15 changes: 15 additions & 0 deletions examples/perlinLandscape/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)
SET (PROJECT_NAME perlinLandscape)
project(
${PROJECT_NAME}
VERSION 1.0
LANGUAGES CXX)

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
list(APPEND SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} voxelengine glad -lX11 -lglfw -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama)

target_include_directories(${PROJECT_NAME} PRIVATE ../../voxelEngine/include/ ../../depends/include/ ../../depends/include/glad/ src/)


7 changes: 4 additions & 3 deletions examples/perlinLandscape/PerlinNoise.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "PerlinNoise.h"
#include <cmath>

PerlinNoise::PerlinNoise(int repeat) : _repeat(repeat)
{
Expand Down Expand Up @@ -47,9 +48,9 @@ double PerlinNoise::octavePerlin(double x, double y, double z, int octaves, doub
double PerlinNoise::perlin(double x, double y, double z)
{
if (_repeat > 0) {
x = fmod(x, _repeat);
y = fmod(y, _repeat);
z = fmod(z, _repeat);
x = std::fmod(x, _repeat);
y = std::fmod(y, _repeat);
z = std::fmod(z, _repeat);
}

int xi = (int)x & 255;
Expand Down
2 changes: 1 addition & 1 deletion examples/perlinLandscape/perlinLandscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void error_callback(int error, const char* description);
int main(int argc, char** argv) {
std::string programPath(argv[0]);
size_t lastSlash = programPath.find_last_of('\\');
std::string shaderPath = programPath.substr(0, lastSlash) + "\\shaders\\";
std::string shaderPath = "shaders/";

GLFWwindow* window;
if (setupEnvironment(window)) return -1;
Expand Down
2 changes: 1 addition & 1 deletion examples/perlinLandscape/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
//#include <tchar.h>



Expand Down
2 changes: 1 addition & 1 deletion examples/perlinLandscape/targetver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>
//#include <SDKDDKVer.h>
15 changes: 15 additions & 0 deletions examples/sprites/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)
SET (PROJECT_NAME sprites)
project(
${PROJECT_NAME}
VERSION 1.0
LANGUAGES CXX)

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
list(APPEND SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} voxelengine glad -lX11 -lglfw -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama)

target_include_directories(${PROJECT_NAME} PRIVATE ../../voxelEngine/include/ ../../depends/include/ ../../depends/include/glad/ src/)


4 changes: 2 additions & 2 deletions examples/sprites/sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ static void error_callback(int error, const char* description);
int main(int argc, char** argv) {
std::string programPath(argv[0]);
size_t lastSlash = programPath.find_last_of('\\');
std::string shaderPath = programPath.substr(0, lastSlash) + "\\shaders\\";
std::string spritePath = programPath.substr(0, lastSlash + 1);
std::string shaderPath = "shaders/";
std::string spritePath = "";

GLFWwindow* window;
if (setupEnvironment(window)) return -1;
Expand Down
2 changes: 1 addition & 1 deletion examples/sprites/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
//#include <tchar.h>



Expand Down
2 changes: 1 addition & 1 deletion examples/sprites/targetver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>
//#include <SDKDDKVer.h>
15 changes: 15 additions & 0 deletions examples/voxelInvaders/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)
SET (PROJECT_NAME voxelInvaders)
project(
${PROJECT_NAME}
VERSION 1.0
LANGUAGES CXX)

file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
list(APPEND SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} voxelengine glad -lX11 -lglfw -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama)

target_include_directories(${PROJECT_NAME} PRIVATE ../../voxelEngine/include/ ../../depends/include/ ../../depends/include/glad/ src/)


2 changes: 1 addition & 1 deletion examples/voxelInvaders/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
//#include <tchar.h>



Expand Down
2 changes: 1 addition & 1 deletion examples/voxelInvaders/targetver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>
//#include <SDKDDKVer.h>
4 changes: 2 additions & 2 deletions examples/voxelInvaders/voxelInvaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ static void error_callback(int error, const char* description);
int main(int argc, char** argv) {
std::string programPath(argv[0]);
size_t lastSlash = programPath.find_last_of('\\');
std::string shaderPath = programPath.substr(0, lastSlash) + "\\shaders\\";
std::string spritePath = programPath.substr(0, lastSlash + 1);
std::string shaderPath = "shaders/";
std::string spritePath = "";

GLFWwindow* window;
if (setupEnvironment(window)) return -1;
Expand Down
79 changes: 79 additions & 0 deletions voxelEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
cmake_minimum_required(VERSION 3.10)

project(
SimpleVoxelEngine
VERSION 1.0
LANGUAGES CXX)


add_library(voxelengine src/AABBTree.cpp
src/AABBTree.h
src/BehaviourFactory.cpp
src/Camera.cpp
src/Camera.h
src/Chunk.cpp
src/ChunkManager.cpp
src/ChunkManager.h
src/Controls.cpp
src/Controls.hpp
src/FrameCounter.h
src/ISprite.cpp
src/IVoxel.cpp
src/MouseAndKeyboardCameraControllerInput.cpp
src/NotImplementedException.h
src/NullCameraController.h
src/ShaderManager.cpp
src/ShaderManager.h
src/SpriteCollisionSet.h
src/SpriteManager.cpp
src/SpriteManager.h
src/SpriteVoxel.h
src/targetver.h
src/UniformChunk.cpp
src/VoxelContainerGeometry.cpp
src/VoxelContainerGeometry.h
src/VoxelEngine.cpp
src/VoxelGeometry.cpp
src/VoxelGeometry.h
src/VoxelRenderer.cpp
src/VoxelRenderer.h
src/VoxelSprite.cpp
src/VoxelSprite.h
src/behaviours/VoxelatedConstructionSpriteBehaviour.cpp
src/behaviours/VoxelatedConstructionSpriteBehaviour.h
src/shaders/grass.fragmentshader
src/shaders/simpleLightColor.fragmentshader
src/shaders/simpleLightTransform.vertexshader
src/shaders/simpleTransform.vertexshader
src/shaders/simple.vertexshader
include/AABB.h
include/BehaviourFactory.h
include/Chunk.h
include/color.h
include/GeometryUpdateRequest.h
include/IAABB.h
include/ICameraControllerInput.h
include/ICamera.h
include/IChunkFactory.h
include/IChunk.h
include/IChunkManager.h
include/ILightSource.h
include/ISpriteBehaviour.h
include/ISpriteCollisionSet.h
include/ISprite.h
include/ISpriteManager.h
include/ISpriteVoxel.h
include/IVoxelContainer.h
include/IVoxel.h
include/MouseAndKeyboardCameraControllerInput.h
include/SimpleLight.h
include/SpriteCollision.h
include/UniformChunk.h
include/VoxelEngineException.h
include/VoxelEngine.h
include/worldSize.h
)

target_include_directories(voxelengine PRIVATE include/ ../depends/include/ src/)


Loading