From 738f244bdcb9a93fc8ad0924b92c2cde65e90946 Mon Sep 17 00:00:00 2001 From: yangosoft Date: Wed, 17 Aug 2022 11:34:06 +0200 Subject: [PATCH 1/3] Initial Linux support --- voxelEngine/CMakeLists.txt | 79 +++++++++++++++++++ voxelEngine/include/ISprite.h | 1 + .../MouseAndKeyboardCameraControllerInput.h | 2 +- voxelEngine/src/Camera.cpp | 4 + voxelEngine/src/Controls.cpp | 4 +- voxelEngine/src/ISprite.cpp | 3 +- voxelEngine/src/ShaderManager.h | 3 +- voxelEngine/src/VoxelRenderer.cpp | 2 +- voxelEngine/src/VoxelSprite.cpp | 2 + voxelEngine/src/VoxelSprite.h | 6 +- 10 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 voxelEngine/CMakeLists.txt diff --git a/voxelEngine/CMakeLists.txt b/voxelEngine/CMakeLists.txt new file mode 100644 index 0000000..22119e8 --- /dev/null +++ b/voxelEngine/CMakeLists.txt @@ -0,0 +1,79 @@ +cmake_minimum_required(VERSION 3.10) + +project( + SimpleVoxelEngine + VERSION 1.0 + LANGUAGES CXX) + + +add_library(voxelengine ../depends/src/glad/glad.c 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/) + + diff --git a/voxelEngine/include/ISprite.h b/voxelEngine/include/ISprite.h index 1747377..cc0c64f 100644 --- a/voxelEngine/include/ISprite.h +++ b/voxelEngine/include/ISprite.h @@ -6,6 +6,7 @@ #include "AABB.h" #include #include "IAABB.h" +#include #include class ISpriteBehaviour; diff --git a/voxelEngine/include/MouseAndKeyboardCameraControllerInput.h b/voxelEngine/include/MouseAndKeyboardCameraControllerInput.h index bc46991..9ff9302 100644 --- a/voxelEngine/include/MouseAndKeyboardCameraControllerInput.h +++ b/voxelEngine/include/MouseAndKeyboardCameraControllerInput.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include "ICameraControllerInput.h" #include diff --git a/voxelEngine/src/Camera.cpp b/voxelEngine/src/Camera.cpp index 7909628..fd785f7 100644 --- a/voxelEngine/src/Camera.cpp +++ b/voxelEngine/src/Camera.cpp @@ -2,6 +2,8 @@ #include "ICameraControllerInput.h" #include +#include "glm/gtc/matrix_transform.hpp" + // default camera position is at world origin looking towards -z Camera::Camera() : Camera(0.0f, 0.0f, 0.0f, 3.14f, 0.0f, 60.0f, 200.0f) { @@ -59,6 +61,8 @@ void Camera::update(const ICameraControllerInput& controllerInput) // projection matrix: field of View, display ratio (4:3), display range _projectionMatrix = glm::perspective(glm::radians(_fieldOfView), _ratio, _nearDepth, _farDepth); // Camera matrix + + _viewMatrix = glm::lookAt( _position, // Camera is here _position + direction, // and looks here : at the same position, plus "direction" diff --git a/voxelEngine/src/Controls.cpp b/voxelEngine/src/Controls.cpp index 5de9b35..b5866e4 100644 --- a/voxelEngine/src/Controls.cpp +++ b/voxelEngine/src/Controls.cpp @@ -1,5 +1,5 @@ // Include GLFW -#include +#include extern GLFWwindow* window; // The "extern" keyword here is to access the variable "window" declared in tutorialXXX.cpp. This is a hack to keep the tutorials simple. Please avoid this. // Include GLM @@ -7,7 +7,7 @@ extern GLFWwindow* window; // The "extern" keyword here is to access the variabl #include using namespace glm; -#include "controls.hpp" +#include "Controls.hpp" glm::mat4 ViewMatrix; glm::mat4 ProjectionMatrix; diff --git a/voxelEngine/src/ISprite.cpp b/voxelEngine/src/ISprite.cpp index 8e7041f..a8a0733 100644 --- a/voxelEngine/src/ISprite.cpp +++ b/voxelEngine/src/ISprite.cpp @@ -1,6 +1,7 @@ #include "ISprite.h" #include #include +#include #include "VoxelSprite.h" #include #include "SpriteVoxel.h" @@ -97,7 +98,7 @@ std::shared_ptr>> loadSpriteVoxels(std std::vector voxels; MV_RGBA palette[256]; - memcpy(palette, mv_default_palette, sizeof(mv_default_palette)); + std::memcpy(palette, mv_default_palette, sizeof(mv_default_palette)); std::ifstream spriteStream(spriteFilename, std::ios::in | std::ios::binary); if (!spriteStream.is_open()) diff --git a/voxelEngine/src/ShaderManager.h b/voxelEngine/src/ShaderManager.h index 81a0501..b6e78da 100644 --- a/voxelEngine/src/ShaderManager.h +++ b/voxelEngine/src/ShaderManager.h @@ -1,7 +1,8 @@ #pragma once -#include +#include #include #include +#include class ShaderManager { diff --git a/voxelEngine/src/VoxelRenderer.cpp b/voxelEngine/src/VoxelRenderer.cpp index 1f7e2a6..de0a431 100644 --- a/voxelEngine/src/VoxelRenderer.cpp +++ b/voxelEngine/src/VoxelRenderer.cpp @@ -1,7 +1,7 @@ #include #include #include "VoxelRenderer.h" -#include "controls.hpp" +#include "Controls.hpp" #include "ICamera.h" #include "ILightSource.h" #include "ShaderManager.h" diff --git a/voxelEngine/src/VoxelSprite.cpp b/voxelEngine/src/VoxelSprite.cpp index 3004303..a46f7c7 100644 --- a/voxelEngine/src/VoxelSprite.cpp +++ b/voxelEngine/src/VoxelSprite.cpp @@ -4,6 +4,7 @@ #include "ISpriteBehaviour.h" #include "ISpriteManager.h" #include +#include #include VoxelSprite::VoxelSprite(const spriteSize& spriteSize, const spriteVec3& spritePosition) : @@ -105,6 +106,7 @@ void VoxelSprite::render(const ICamera& camera, const ILightSource& light) const { const VoxelSpriteFramePtr& frame = getCurrentFrame(); if (frame->renderer == nullptr) return; + frame->renderer->render(camera, *frame->geometry, light, glm::translate(glm::mat4(1.0f), glm::vec3(_position.x, _position.y, _position.z))); } diff --git a/voxelEngine/src/VoxelSprite.h b/voxelEngine/src/VoxelSprite.h index 5ecc8e7..bb38cd9 100644 --- a/voxelEngine/src/VoxelSprite.h +++ b/voxelEngine/src/VoxelSprite.h @@ -58,7 +58,7 @@ class VoxelSprite : public ISprite, public IVoxelContainer, public std::enable_s VoxelSpriteFramePtr getCurrentFrame() const { return _frames[_frameIndex]; } public: - VoxelSprite::VoxelSprite(const spriteSize& spriteSize, const spriteVec3& spritePosition); + VoxelSprite(const spriteSize& spriteSize, const spriteVec3& spritePosition); VoxelSprite(const spriteSize& spriteSize, const spriteVec3& spritePosition, const std::vector>& voxels); VoxelSprite(const spriteSize& spriteSize, const spriteVec3& spritePosition, const std::vector>>& frameVoxels, float timeBetweenFrames, float frameChangeDeferral=0.0f); spriteSize getSize() const override { return _size; }; @@ -74,8 +74,8 @@ class VoxelSprite : public ISprite, public IVoxelContainer, public std::enable_s void render(const ICamera& camera, const ILightSource& light) const override; void rebuildGeometry() override; void prepareRenderer() override; - std::shared_ptr VoxelSprite::getVoxel(unsigned int x, unsigned int y, unsigned int z) const override; - void VoxelSprite::setVoxel(unsigned int x, unsigned int y, unsigned int z, const std::shared_ptr& voxel) const; + std::shared_ptr getVoxel(unsigned int x, unsigned int y, unsigned int z) const override; + void setVoxel(unsigned int x, unsigned int y, unsigned int z, const std::shared_ptr& voxel) const; unsigned getContainerWidthInVoxels() const override { return _size.width; } unsigned getContainerHeightInVoxels() const override { return _size.height; } unsigned getContainerDepthInVoxels() const override { return _size.depth; } From 0a8397531f68118ed70cbc4586f64807bc6341d2 Mon Sep 17 00:00:00 2001 From: yangosoft Date: Wed, 17 Aug 2022 11:45:51 +0200 Subject: [PATCH 2/3] Added Readme file --- voxelEngine/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 voxelEngine/README.md diff --git a/voxelEngine/README.md b/voxelEngine/README.md new file mode 100644 index 0000000..2380fe5 --- /dev/null +++ b/voxelEngine/README.md @@ -0,0 +1,11 @@ +Initial compilation for Linux. +Added a CMakeLists.txt +Fixed some includes. +To compile in Ubuntu: + +``` +$ sudo apt-get install glew-utils libglew-dev libglm-dev libglfw3-dev +$ mv depends/include/glm depends/include/_glm +$ cd voxelEngine ; mkdir build ; cd build +$ make -j 8 +``` \ No newline at end of file From 805815e63e45907dc4d4406a37da47a21c0cbce5 Mon Sep 17 00:00:00 2001 From: yangosoft Date: Wed, 17 Aug 2022 13:10:32 +0200 Subject: [PATCH 3/3] Build examples and glad library --- CMakeLists.txt | 12 ++++ README.md | 11 +++ depends/CMakeLists.txt | 7 ++ depends/include/glm/CMakeLists.txt | 67 ------------------- examples/CMakeLists.txt | 7 ++ examples/bwImageHeightMap/CMakeLists.txt | 15 +++++ .../ImageSourceChunkFactory.cpp | 2 + .../bwImageHeightMap/bwImageHeightMap.cpp | 8 +-- examples/bwImageHeightMap/stdafx.h | 4 +- examples/perlinLandscape/CMakeLists.txt | 15 +++++ examples/perlinLandscape/PerlinNoise.cpp | 7 +- examples/perlinLandscape/perlinLandscape.cpp | 2 +- examples/perlinLandscape/stdafx.h | 2 +- examples/perlinLandscape/targetver.h | 2 +- examples/sprites/CMakeLists.txt | 15 +++++ examples/sprites/sprites.cpp | 4 +- examples/sprites/stdafx.h | 2 +- examples/sprites/targetver.h | 2 +- examples/voxelInvaders/CMakeLists.txt | 15 +++++ examples/voxelInvaders/stdafx.h | 2 +- examples/voxelInvaders/targetver.h | 2 +- examples/voxelInvaders/voxelInvaders.cpp | 4 +- voxelEngine/CMakeLists.txt | 2 +- voxelEngine/include/SimpleLight.h | 2 +- voxelEngine/src/VoxelRenderer.cpp | 10 ++- 25 files changed, 130 insertions(+), 91 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 depends/CMakeLists.txt delete mode 100644 depends/include/glm/CMakeLists.txt create mode 100644 examples/CMakeLists.txt create mode 100644 examples/bwImageHeightMap/CMakeLists.txt create mode 100644 examples/perlinLandscape/CMakeLists.txt create mode 100644 examples/sprites/CMakeLists.txt create mode 100644 examples/voxelInvaders/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ddd1749 --- /dev/null +++ b/CMakeLists.txt @@ -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) + + diff --git a/README.md b/README.md index bed86f7..d1fe6e6 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt new file mode 100644 index 0000000..c92d16b --- /dev/null +++ b/depends/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.10) + +add_library(glad src/glad/glad.cpp) + +target_include_directories(glad PRIVATE include/) + + diff --git a/depends/include/glm/CMakeLists.txt b/depends/include/glm/CMakeLists.txt deleted file mode 100644 index d60a887..0000000 --- a/depends/include/glm/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -file(GLOB ROOT_SOURCE *.cpp) -file(GLOB ROOT_INLINE *.inl) -file(GLOB ROOT_HEADER *.hpp) -file(GLOB ROOT_TEXT ../*.txt) -file(GLOB ROOT_MD ../*.md) -file(GLOB ROOT_NAT ../util/glm.natvis) - -file(GLOB_RECURSE CORE_SOURCE ./detail/*.cpp) -file(GLOB_RECURSE CORE_INLINE ./detail/*.inl) -file(GLOB_RECURSE CORE_HEADER ./detail/*.hpp) - -file(GLOB_RECURSE GTC_SOURCE ./gtc/*.cpp) -file(GLOB_RECURSE GTC_INLINE ./gtc/*.inl) -file(GLOB_RECURSE GTC_HEADER ./gtc/*.hpp) - -file(GLOB_RECURSE GTX_SOURCE ./gtx/*.cpp) -file(GLOB_RECURSE GTX_INLINE ./gtx/*.inl) -file(GLOB_RECURSE GTX_HEADER ./gtx/*.hpp) - -file(GLOB_RECURSE SIMD_SOURCE ./simd/*.cpp) -file(GLOB_RECURSE SIMD_INLINE ./simd/*.inl) -file(GLOB_RECURSE SIMD_HEADER ./simd/*.h) - -source_group("Text Files" FILES ${ROOT_TEXT} ${ROOT_MD}) -source_group("Core Files" FILES ${CORE_SOURCE}) -source_group("Core Files" FILES ${CORE_INLINE}) -source_group("Core Files" FILES ${CORE_HEADER}) -source_group("GTC Files" FILES ${GTC_SOURCE}) -source_group("GTC Files" FILES ${GTC_INLINE}) -source_group("GTC Files" FILES ${GTC_HEADER}) -source_group("GTX Files" FILES ${GTX_SOURCE}) -source_group("GTX Files" FILES ${GTX_INLINE}) -source_group("GTX Files" FILES ${GTX_HEADER}) -source_group("SIMD Files" FILES ${SIMD_SOURCE}) -source_group("SIMD Files" FILES ${SIMD_INLINE}) -source_group("SIMD Files" FILES ${SIMD_HEADER}) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) - -if(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) - if(GLM_STATIC_LIBRARY_ENABLE) - add_library(glm_static STATIC ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} - ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} - ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} - ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} - ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} - ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) - endif(GLM_STATIC_LIBRARY_ENABLE) - - if(GLM_DYNAMIC_LIBRARY_ENABLE) - add_library(glm_shared SHARED ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} - ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} - ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} - ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} - ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} - ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) - endif(GLM_DYNAMIC_LIBRARY_ENABLE) - -else(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) - add_executable(glm_dummy ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT} - ${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER} - ${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER} - ${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER} - ${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER} - ${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}) - -endif(GLM_STATIC_LIBRARY_ENABLE OR GLM_DYNAMIC_LIBRARY_ENABLE) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..07e96f5 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.10) +add_subdirectory(bwImageHeightMap) +add_subdirectory(perlinLandscape) +add_subdirectory(sprites) +add_subdirectory(voxelInvaders) + + diff --git a/examples/bwImageHeightMap/CMakeLists.txt b/examples/bwImageHeightMap/CMakeLists.txt new file mode 100644 index 0000000..5587e55 --- /dev/null +++ b/examples/bwImageHeightMap/CMakeLists.txt @@ -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/) + + diff --git a/examples/bwImageHeightMap/ImageSourceChunkFactory.cpp b/examples/bwImageHeightMap/ImageSourceChunkFactory.cpp index 286b321..c52c9e6 100644 --- a/examples/bwImageHeightMap/ImageSourceChunkFactory.cpp +++ b/examples/bwImageHeightMap/ImageSourceChunkFactory.cpp @@ -3,6 +3,8 @@ #include "IChunkManager.h" #include "GreyScaleVoxel.h" +#include + ImageSourceChunkFactory::ImageSourceChunkFactory(std::string sourceImageFilename, bool inverseHeight, bool inverseColor, bool isBlackAndWhite) : _image(sourceImageFilename.c_str()), _inverseHeight(inverseHeight), _inverseColor(inverseColor), _isBlackAndWhite(isBlackAndWhite) { diff --git a/examples/bwImageHeightMap/bwImageHeightMap.cpp b/examples/bwImageHeightMap/bwImageHeightMap.cpp index d26836f..251f134 100644 --- a/examples/bwImageHeightMap/bwImageHeightMap.cpp +++ b/examples/bwImageHeightMap/bwImageHeightMap.cpp @@ -1,4 +1,4 @@ -#include +#include "glad/glad.h" #include #include "VoxelEngine.h" #include "ImageSourceChunkFactory.h" @@ -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 chunkFactory = std::make_shared(".\\sourceImageVerySmall.bmp", false, false); - std::shared_ptr chunkFactory = std::make_shared(".\\sourceImageVerySmall.bmp", false, false); + //std::shared_ptr chunkFactory = std::make_shared("sourceImageVerySmall.bmp", false, false); + std::shared_ptr chunkFactory = std::make_shared("sourceImageVerySmall.bmp", false, false); worldSize worldDimensions(chunkFactory->requiredWidth(), 3 * IChunk::Height, chunkFactory->requiredDepth()); std::shared_ptr cameraInputController = std::make_shared(window, 0.005f, 64.0f); std::shared_ptr light = std::make_shared(lightSourcePosition(50.0f, 400.0f, 50.0f), color(1.0f, 1.0f, 1.0f), 128000.0f); diff --git a/examples/bwImageHeightMap/stdafx.h b/examples/bwImageHeightMap/stdafx.h index b005a83..d620a35 100644 --- a/examples/bwImageHeightMap/stdafx.h +++ b/examples/bwImageHeightMap/stdafx.h @@ -5,10 +5,10 @@ #pragma once -#include "targetver.h" +//#include "targetver.h" #include -#include +//#include diff --git a/examples/perlinLandscape/CMakeLists.txt b/examples/perlinLandscape/CMakeLists.txt new file mode 100644 index 0000000..3746d70 --- /dev/null +++ b/examples/perlinLandscape/CMakeLists.txt @@ -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/) + + diff --git a/examples/perlinLandscape/PerlinNoise.cpp b/examples/perlinLandscape/PerlinNoise.cpp index 668dca0..4487bfe 100644 --- a/examples/perlinLandscape/PerlinNoise.cpp +++ b/examples/perlinLandscape/PerlinNoise.cpp @@ -1,4 +1,5 @@ #include "PerlinNoise.h" +#include PerlinNoise::PerlinNoise(int repeat) : _repeat(repeat) { @@ -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; diff --git a/examples/perlinLandscape/perlinLandscape.cpp b/examples/perlinLandscape/perlinLandscape.cpp index 5f26d85..a286b9f 100644 --- a/examples/perlinLandscape/perlinLandscape.cpp +++ b/examples/perlinLandscape/perlinLandscape.cpp @@ -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; diff --git a/examples/perlinLandscape/stdafx.h b/examples/perlinLandscape/stdafx.h index b005a83..5d24261 100644 --- a/examples/perlinLandscape/stdafx.h +++ b/examples/perlinLandscape/stdafx.h @@ -8,7 +8,7 @@ #include "targetver.h" #include -#include +//#include diff --git a/examples/perlinLandscape/targetver.h b/examples/perlinLandscape/targetver.h index 87c0086..b8da604 100644 --- a/examples/perlinLandscape/targetver.h +++ b/examples/perlinLandscape/targetver.h @@ -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 +//#include diff --git a/examples/sprites/CMakeLists.txt b/examples/sprites/CMakeLists.txt new file mode 100644 index 0000000..9800ec1 --- /dev/null +++ b/examples/sprites/CMakeLists.txt @@ -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/) + + diff --git a/examples/sprites/sprites.cpp b/examples/sprites/sprites.cpp index 24dcc63..7682677 100644 --- a/examples/sprites/sprites.cpp +++ b/examples/sprites/sprites.cpp @@ -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; diff --git a/examples/sprites/stdafx.h b/examples/sprites/stdafx.h index b005a83..5d24261 100644 --- a/examples/sprites/stdafx.h +++ b/examples/sprites/stdafx.h @@ -8,7 +8,7 @@ #include "targetver.h" #include -#include +//#include diff --git a/examples/sprites/targetver.h b/examples/sprites/targetver.h index 87c0086..b8da604 100644 --- a/examples/sprites/targetver.h +++ b/examples/sprites/targetver.h @@ -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 +//#include diff --git a/examples/voxelInvaders/CMakeLists.txt b/examples/voxelInvaders/CMakeLists.txt new file mode 100644 index 0000000..70dc88a --- /dev/null +++ b/examples/voxelInvaders/CMakeLists.txt @@ -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/) + + diff --git a/examples/voxelInvaders/stdafx.h b/examples/voxelInvaders/stdafx.h index b005a83..5d24261 100644 --- a/examples/voxelInvaders/stdafx.h +++ b/examples/voxelInvaders/stdafx.h @@ -8,7 +8,7 @@ #include "targetver.h" #include -#include +//#include diff --git a/examples/voxelInvaders/targetver.h b/examples/voxelInvaders/targetver.h index 87c0086..b8da604 100644 --- a/examples/voxelInvaders/targetver.h +++ b/examples/voxelInvaders/targetver.h @@ -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 +//#include diff --git a/examples/voxelInvaders/voxelInvaders.cpp b/examples/voxelInvaders/voxelInvaders.cpp index e647a61..502befa 100644 --- a/examples/voxelInvaders/voxelInvaders.cpp +++ b/examples/voxelInvaders/voxelInvaders.cpp @@ -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; diff --git a/voxelEngine/CMakeLists.txt b/voxelEngine/CMakeLists.txt index 22119e8..0d434bd 100644 --- a/voxelEngine/CMakeLists.txt +++ b/voxelEngine/CMakeLists.txt @@ -6,7 +6,7 @@ project( LANGUAGES CXX) -add_library(voxelengine ../depends/src/glad/glad.c src/AABBTree.cpp +add_library(voxelengine src/AABBTree.cpp src/AABBTree.h src/BehaviourFactory.cpp src/Camera.cpp diff --git a/voxelEngine/include/SimpleLight.h b/voxelEngine/include/SimpleLight.h index b103792..5a60a87 100644 --- a/voxelEngine/include/SimpleLight.h +++ b/voxelEngine/include/SimpleLight.h @@ -8,7 +8,7 @@ class SimpleLight : public ILightSource float _power; public: SimpleLight(const lightSourcePosition& position, const color& color, float power) : _position(position), _color(color), _power(power) { } - __thiscall ~SimpleLight() override { }; + virtual ~SimpleLight() override { }; lightSourcePosition getPosition() const override { return _position; } float getPower() const override { return _power; } color getColor() const override { return _color; } diff --git a/voxelEngine/src/VoxelRenderer.cpp b/voxelEngine/src/VoxelRenderer.cpp index de0a431..9301aec 100644 --- a/voxelEngine/src/VoxelRenderer.cpp +++ b/voxelEngine/src/VoxelRenderer.cpp @@ -1,3 +1,4 @@ +#include "glad/glad.h" #include #include #include "VoxelRenderer.h" @@ -6,6 +7,8 @@ #include "ILightSource.h" #include "ShaderManager.h" +#include + VoxelRenderer::VoxelRenderer(): _normalBuffer(0) { _vertexBuffer = 0; @@ -88,6 +91,7 @@ void VoxelRenderer::rebindVisibility(const VoxelContainerGeometry& chunkGeometry void VoxelRenderer::render(const ICamera& camera, const VoxelContainerGeometry& chunkGeometry, const ILightSource& light, glm::mat4 modelMatrix) const { + if (chunkGeometry.needsRendering()) { glBindVertexArray(_vertexArrayId); @@ -101,8 +105,9 @@ void VoxelRenderer::render(const ICamera& camera, const VoxelContainerGeometry& GLuint lightPowerID = glGetUniformLocation(shaderId, "LightPower"); GLuint lightColorID = glGetUniformLocation(shaderId, "LightColor"); + std::cout << "glUseProgram" << std::endl; glUseProgram(shaderId); - +std::cout << "~glUseProgram" << std::endl; // camera glm::mat4 ProjectionMatrix = camera.getProjectionMatrix(); glm::mat4 ViewMatrix = camera.getViewMatrix(); @@ -164,8 +169,9 @@ void VoxelRenderer::render(const ICamera& camera, const VoxelContainerGeometry& 0, (void*)0 ); - +std::cout << "glDrawArrays" << std::endl; glDrawArrays(GL_TRIANGLES, 0, _numberOfVertices); + std::cout << "~glDrawArrays" << std::endl; glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); }