Made code possible to compile on linux

This commit is contained in:
Dawid Pietrykowski 2023-06-04 18:27:34 +02:00
parent b2e43b2ea7
commit 133701c417
6 changed files with 67 additions and 40 deletions

View File

@ -55,33 +55,35 @@ set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h #find_path(GLFW_INCLUDE_DIR GLFW/glfw3.h
HINTS #HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include #${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/lib #${CMAKE_CURRENT_SOURCE_DIR}/lib
${GLFW_ROOT} #${GLFW_ROOT}
${GLFW_ROOT}/include) #${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) find_package(glfw3 REQUIRED)
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 GLEW # Find GLEW
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
@ -102,11 +104,13 @@ endif()
# Find stb_image # Find stb_image
find_path(stb_image_INCLUDE_DIR stb_image.h find_path(stb_image_INCLUDE_DIR stb_image.h
HINTS HINTS
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/stb ${CMAKE_CURRENT_SOURCE_DIR}/include/stb
${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/lib
${stb_image_ROOT}) ${CMAKE_CURRENT_SOURCE_DIR}
"/usr/include/stb"
${stb_image_ROOT})
if(stb_image_INCLUDE_DIR) if(stb_image_INCLUDE_DIR)
message(STATUS "stb_image_INCLUDE_DIR: ${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} ${stb_image_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}) ${GLEW_INCLUDE_DIR})
target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES}) 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 # Header files
file(COPY src/ComputeEngine.h DESTINATION ${CMAKE_BINARY_DIR}/include) file(COPY src/ComputeEngine.h DESTINATION ${CMAKE_BINARY_DIR}/include)

1
build.nu Executable file
View File

@ -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

View File

@ -1,4 +1,10 @@
#include <Windows.h> #ifdef _WIN32
#include <windows.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include "ComputeEngine.h" #include "ComputeEngine.h"
@ -16,7 +22,10 @@
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include <string> #include <string>
#include <fileapi.h>
#ifdef _WIN32
#include <fileapi.h>
#endif
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -289,7 +298,11 @@ void ComputeEngine::SaveScreen(std::string name) {
} }
const char* path = "screenshots"; const char* path = "screenshots";
#ifdef _WIN32
CreateDirectoryA(path, NULL); CreateDirectoryA(path, NULL);
#else
mkdir(path, 0777);
#endif
name = name + std::to_string(i) + ".png"; name = name + std::to_string(i) + ".png";

View File

@ -4,17 +4,23 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#ifdef _MSC_VER
#define DEBUG_BREAK __debugbreak();
#else
#include <csignal>
#define DEBUG_BREAK raise(SIGTRAP);
#endif
#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define ASSERT(x) if(!(x)){ std::cout << "[ERROR] " << #x << '\n';\ #define ASSERT(x) if(!(x)){ std::cout << "[ERROR] " << #x << '\n';\
__debugbreak();} DEBUG_BREAK}
#define GLCall(x) \ #define GLCall(x) \
glClearError();\ glClearError();\
x;\ x;\
if(!(glErrorCheck())){ std::cout << "[ERROR] " << #x << '\n';\ if(!(glErrorCheck())){ std::cout << "[ERROR] " << #x << '\n';\
__debugbreak();} DEBUG_BREAK}
#if 1 #if 1
#define LOG(msg) \ #define LOG(msg) \

View File

@ -7,6 +7,8 @@
#include "Texture.h" #include "Texture.h"
#include "Shader.h" #include "Shader.h"
#include <cmath>
Program::Program() : Program::Program() :
m_id(0) m_id(0)
{ {
@ -71,8 +73,8 @@ void Program::Delete() {
void Program::DispatchCompute(int width, int height) { void Program::DispatchCompute(int width, int height) {
Use(); Use();
int up_w = int(ceil((float)width / 8.0f)); int up_w = int(std::ceil((float)width / 8.0f));
int up_h = int(ceil((float)height / 8.0f)); int up_h = int(std::ceil((float)height / 8.0f));
GLCall(glDispatchCompute(up_w, up_h, 1)); GLCall(glDispatchCompute(up_w, up_h, 1));
} }

View File

@ -89,7 +89,7 @@ Shader::Shader(unsigned int type, bool tonemapped) {
m_id = CompileShader(frag_source_tonemapped, type); m_id = CompileShader(frag_source_tonemapped, type);
break; break;
default: default:
__debugbreak(); DEBUG_BREAK
break; break;
} }
} }