From e184b1c9108d0b42a9d1a2cfa59d0784bb593756 Mon Sep 17 00:00:00 2001 From: illegitimate-egg Date: Sun, 6 Oct 2024 09:02:32 +0100 Subject: [PATCH] Update trying for a Windows baby --- .gitmodules | 3 +++ CMakeLists.txt | 23 +++++++++++++++++------ engine.cpp | 13 +++++++------ include/CLog | 1 + shader.c | 24 ++++++++++++++++-------- 5 files changed, 44 insertions(+), 20 deletions(-) create mode 160000 include/CLog diff --git a/.gitmodules b/.gitmodules index 8798a8c..151ca33 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "include/imgui"] path = include/imgui url = https://github.com/ocornut/imgui +[submodule "include/CLog"] + path = include/CLog + url = https://github.com/williamistGitHub/CLog.git diff --git a/CMakeLists.txt b/CMakeLists.txt index cff82a2..6e41428 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,17 +19,27 @@ if(CMAKE_BIANRY_DIR MATCHES " ") message("Spaces in the build dir can cause errors, thou art been warned") endif() -add_custom_command( - OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c - ${PROJECT_SOURCE_DIR}/include/glewinfo.c - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto - COMMAND ${CMAKE_MAKE_PROGRAM}) +if(LINUX) + add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c + ${PROJECT_SOURCE_DIR}/include/glewinfo.c + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto + COMMAND ${CMAKE_MAKE_PROGRAM}) +endif() +if(WIN32) + add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/include (glew) /src/glew.c + ${PROJECT_SOURCE_DIR}/include/glewinfo.c + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/build/vc15 + COMMAND ${CMAKE_VS_MSBUILD_COMMAND}) +endif() add_subdirectory(include/glm) add_subdirectory(include/glew/build/cmake) add_subdirectory(include/glfw) add_subdirectory(include/SOIL2) add_subdirectory(include/assimp) +add_subdirectory(include/CLog) include_directories(include/imgui) add_library( @@ -52,4 +62,5 @@ target_link_libraries( glfw soil2 assimp - imgui) + imgui + clog) diff --git a/engine.cpp b/engine.cpp index ead91fd..12d2bf7 100644 --- a/engine.cpp +++ b/engine.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,7 @@ extern "C" { #define HEIGHT 768 static void glfwErrorCallback(int e, const char *description) { - fprintf(stderr, "GLFW Error %d: %s", e, description); + clog_log(CLOG_LEVEL_ERROR, "GLFW Error %d: %s", e, description); } bool loadModel(const char *path, std::vector &indices, @@ -40,7 +41,7 @@ bool loadModel(const char *path, std::vector &indices, path, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); if (!scene) { - fprintf(stderr, "%s\n", importer.GetErrorString()); + clog_log(CLOG_LEVEL_ERROR, "%s", importer.GetErrorString()); return false; } const aiMesh *mesh = scene->mMeshes[0]; @@ -72,7 +73,7 @@ int initWindow() { glewExperimental = true; if (!glfwInit()) { - fprintf(stderr, "GLFW went shitty time\n"); + clog_log(CLOG_LEVEL_ERROR, "GLFW went shitty time (failed to init)"); return 1; } @@ -85,7 +86,7 @@ int initWindow() { GLFWwindow *window; window = glfwCreateWindow(WIDTH, HEIGHT, "Fred", NULL, NULL); if (window == NULL) { - fprintf(stderr, "Failed to open window.\n"); + clog_log(CLOG_LEVEL_ERROR, "Failed to open window."); glfwTerminate(); return 1; } @@ -94,7 +95,7 @@ int initWindow() { glfwSwapInterval(1); int code; if ((code = glewInit()) != GLEW_OK) { - fprintf(stderr, "Failed to init GLEW: %s\n", glewGetErrorString(code)); + clog_log(CLOG_LEVEL_ERROR, "Failed to init GLEW: %s", glewGetErrorString(code)); return 1; } @@ -152,7 +153,7 @@ int initWindow() { SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); if (texture == 0) { - printf("Texture failed to load\n"); + clog_log(CLOG_LEVEL_WARN, "Texture failed to load"); return 0; } diff --git a/include/CLog b/include/CLog new file mode 160000 index 0000000..5a8dc48 --- /dev/null +++ b/include/CLog @@ -0,0 +1 @@ +Subproject commit 5a8dc48b060619da1b6fbbacd18630c4d2c92182 diff --git a/shader.c b/shader.c index 3d169bc..5f23c22 100644 --- a/shader.c +++ b/shader.c @@ -3,7 +3,15 @@ #include #include +#ifdef __linux__ #include +#endif +#ifdef _WIN32 +#include +#define lseek _lseek +#endif + +#include GLuint loadShaders(const char *vertex_file_path, const char *fragment_file_path) { @@ -14,7 +22,7 @@ GLuint loadShaders(const char *vertex_file_path, vertexShaderFD = fopen(vertex_file_path, "rb"); if (vertexShaderFD == NULL) { fclose(vertexShaderFD); - fprintf(stderr, "Failed to open Vertex Shader"); + clog_log(CLOG_LEVEL_ERROR, "Failed to open Vertex Shader"); return 1; } int vertexShaderLength = lseek(fileno(vertexShaderFD), 0L, SEEK_END) + 1; @@ -28,7 +36,7 @@ GLuint loadShaders(const char *vertex_file_path, fragmentShaderFD = fopen(fragment_file_path, "rb"); if (fragmentShaderFD == NULL) { fclose(fragmentShaderFD); - fprintf(stderr, "Failed to open Fragment Shader"); + clog_log(CLOG_LEVEL_ERROR, "Failed to open Fragment Shader"); return 1; } int fragmentShaderLength = lseek(fileno(fragmentShaderFD), 0L, SEEK_END) + 1; @@ -41,7 +49,7 @@ GLuint loadShaders(const char *vertex_file_path, GLint result = GL_FALSE; int infoLogLength; - printf("Compiling shader: %s\n", vertex_file_path); + clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", vertex_file_path); char const *vertexShaderCodeConst = vertexShaderCode; glShaderSource(vertexShaderID, 1, &vertexShaderCodeConst, NULL); glCompileShader(vertexShaderID); @@ -52,10 +60,10 @@ GLuint loadShaders(const char *vertex_file_path, char *vertexShaderErrorMessage[infoLogLength + 1]; glGetShaderInfoLog(vertexShaderID, infoLogLength, NULL, *vertexShaderErrorMessage); - printf("%s\n", *vertexShaderErrorMessage); + clog_log(CLOG_LEVEL_ERROR, "%s", *vertexShaderErrorMessage); } - printf("Compiling shader: %s\n", fragment_file_path); + clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", fragment_file_path); char const *fragmentShaderCodeConst = fragmentShaderCode; glShaderSource(fragmentShaderID, 1, &fragmentShaderCodeConst, NULL); glCompileShader(fragmentShaderID); @@ -66,10 +74,10 @@ GLuint loadShaders(const char *vertex_file_path, char *fragmentShaderErrorMessage[infoLogLength + 1]; glGetShaderInfoLog(fragmentShaderID, infoLogLength, NULL, *fragmentShaderErrorMessage); - printf("%s\n", *fragmentShaderErrorMessage); + clog_log(CLOG_LEVEL_ERROR, "%s", *fragmentShaderErrorMessage); } - printf("Linking program\n"); + clog_log(CLOG_LEVEL_DEBUG, "Linking shader program"); GLuint programID = glCreateProgram(); glAttachShader(programID, vertexShaderID); glAttachShader(programID, fragmentShaderID); @@ -80,7 +88,7 @@ GLuint loadShaders(const char *vertex_file_path, if (infoLogLength > 0) { char *programErrorMessage[infoLogLength + 1]; glGetProgramInfoLog(programID, infoLogLength, NULL, *programErrorMessage); - printf("%s\n", *programErrorMessage); + clog_log(CLOG_LEVEL_ERROR, "%s", *programErrorMessage); } glDetachShader(programID, vertexShaderID);