From 133701c4174c00b869988bdc8b21234dc6d5e718 Mon Sep 17 00:00:00 2001 From: Dawid Pietrykowski Date: Sun, 4 Jun 2023 18:27:34 +0200 Subject: [PATCH] Made code possible to compile on linux --- CMakeLists.txt | 71 +++++++++++++++++++++++-------------------- build.nu | 1 + src/ComputeEngine.cpp | 17 +++++++++-- src/GLUtils.h | 10 ++++-- src/Program.cpp | 6 ++-- src/Shader.cpp | 2 +- 6 files changed, 67 insertions(+), 40 deletions(-) create mode 100755 build.nu diff --git a/CMakeLists.txt b/CMakeLists.txt index 711f141..67b38d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,33 +55,35 @@ set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) -find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h -HINTS -${CMAKE_CURRENT_SOURCE_DIR}/include -${CMAKE_CURRENT_SOURCE_DIR}/lib -${GLFW_ROOT} -${GLFW_ROOT}/include) +#find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h +#HINTS +#${CMAKE_CURRENT_SOURCE_DIR}/include +#${CMAKE_CURRENT_SOURCE_DIR}/lib +#${GLFW_ROOT} +#${GLFW_ROOT}/include) +# +#if(GLFW_INCLUDE_DIR) +#message(STATUS "GLFW_INCLUDE_DIR: ${GLFW_INCLUDE_DIR}") +#else() +#message(FATAL_ERROR "glfw3.h not found") +#endif() +# +#find_path(GLFW_LIB_DIR glfw3.lib +#HINTS +#${CMAKE_CURRENT_SOURCE_DIR}/include +#${CMAKE_CURRENT_SOURCE_DIR}/lib +#${GLFW_ROOT}/lib +#${GLFW_ROOT}/lib-vc2019 +#${GLFW_ROOT}/lib-vc2017 +#${GLFW_ROOT}/lib-vc2015) +# +#if(GLFW_LIB_DIR) +#message(STATUS "GLFW_LIB_DIR: ${GLFW_LIB_DIR}") +#else() +#message(FATAL_ERROR "glfw3.lib not found") +#endif() -if(GLFW_INCLUDE_DIR) -message(STATUS "GLFW_INCLUDE_DIR: ${GLFW_INCLUDE_DIR}") -else() -message(FATAL_ERROR "glfw3.h not found") -endif() - -find_path(GLFW_LIB_DIR glfw3.lib -HINTS -${CMAKE_CURRENT_SOURCE_DIR}/include -${CMAKE_CURRENT_SOURCE_DIR}/lib -${GLFW_ROOT}/lib -${GLFW_ROOT}/lib-vc2019 -${GLFW_ROOT}/lib-vc2017 -${GLFW_ROOT}/lib-vc2015) - -if(GLFW_LIB_DIR) -message(STATUS "GLFW_LIB_DIR: ${GLFW_LIB_DIR}") -else() -message(FATAL_ERROR "glfw3.lib not found") -endif() +find_package(glfw3 REQUIRED) # Find GLEW find_package(GLEW REQUIRED) @@ -101,12 +103,14 @@ if(NOT WIN32) endif() # Find stb_image -find_path(stb_image_INCLUDE_DIR stb_image.h -HINTS -${CMAKE_CURRENT_SOURCE_DIR}/include -${CMAKE_CURRENT_SOURCE_DIR}/include/stb -${CMAKE_CURRENT_SOURCE_DIR}/lib -${stb_image_ROOT}) +find_path(stb_image_INCLUDE_DIR stb_image.h + HINTS + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/include/stb + ${CMAKE_CURRENT_SOURCE_DIR}/lib + ${CMAKE_CURRENT_SOURCE_DIR} + "/usr/include/stb" + ${stb_image_ROOT}) if(stb_image_INCLUDE_DIR) message(STATUS "stb_image_INCLUDE_DIR: ${stb_image_INCLUDE_DIR}") @@ -122,7 +126,8 @@ ${OPENGL_INCLUDE_DIR} ${stb_image_INCLUDE_DIR} ${GLEW_INCLUDE_DIR}) target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES}) -target_link_libraries(${PROJECT_NAME} "glfw3.lib" "opengl32.lib" "glew32s.lib") +target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL GLEW::GLEW) + # Header files file(COPY src/ComputeEngine.h DESTINATION ${CMAKE_BINARY_DIR}/include) diff --git a/build.nu b/build.nu new file mode 100755 index 0000000..c81ae8e --- /dev/null +++ b/build.nu @@ -0,0 +1 @@ +rm -rf cmake-build-debug try return 0 ; rm -fr build try return 0 ; cmake -B build -S . ; cmake --build build --config Release diff --git a/src/ComputeEngine.cpp b/src/ComputeEngine.cpp index ea5ab1c..86a58fb 100644 --- a/src/ComputeEngine.cpp +++ b/src/ComputeEngine.cpp @@ -1,4 +1,10 @@ -#include +#ifdef _WIN32 + #include +#else + #include + #include +#endif + #include "ComputeEngine.h" @@ -16,7 +22,10 @@ #include #include #include -#include + +#ifdef _WIN32 + #include +#endif #include #include @@ -289,7 +298,11 @@ void ComputeEngine::SaveScreen(std::string name) { } const char* path = "screenshots"; +#ifdef _WIN32 CreateDirectoryA(path, NULL); +#else + mkdir(path, 0777); +#endif name = name + std::to_string(i) + ".png"; diff --git a/src/GLUtils.h b/src/GLUtils.h index 778d19d..0dac00f 100644 --- a/src/GLUtils.h +++ b/src/GLUtils.h @@ -4,17 +4,23 @@ #include #include +#ifdef _MSC_VER +#define DEBUG_BREAK __debugbreak(); +#else +#include +#define DEBUG_BREAK raise(SIGTRAP); +#endif #define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define ASSERT(x) if(!(x)){ std::cout << "[ERROR] " << #x << '\n';\ -__debugbreak();} +DEBUG_BREAK} #define GLCall(x) \ glClearError();\ x;\ if(!(glErrorCheck())){ std::cout << "[ERROR] " << #x << '\n';\ - __debugbreak();} + DEBUG_BREAK} #if 1 #define LOG(msg) \ diff --git a/src/Program.cpp b/src/Program.cpp index 40af97e..a1a5f2d 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -7,6 +7,8 @@ #include "Texture.h" #include "Shader.h" +#include + Program::Program() : m_id(0) { @@ -71,8 +73,8 @@ void Program::Delete() { void Program::DispatchCompute(int width, int height) { Use(); - int up_w = int(ceil((float)width / 8.0f)); - int up_h = int(ceil((float)height / 8.0f)); + int up_w = int(std::ceil((float)width / 8.0f)); + int up_h = int(std::ceil((float)height / 8.0f)); GLCall(glDispatchCompute(up_w, up_h, 1)); } diff --git a/src/Shader.cpp b/src/Shader.cpp index e50b96e..c9f1158 100644 --- a/src/Shader.cpp +++ b/src/Shader.cpp @@ -89,7 +89,7 @@ Shader::Shader(unsigned int type, bool tonemapped) { m_id = CompileShader(frag_source_tonemapped, type); break; default: - __debugbreak(); + DEBUG_BREAK break; } }