From 79717cfc57b961c0599b0b77d6c65b1c283c0294 Mon Sep 17 00:00:00 2001 From: 4VRDriver <44267643+4VRDriver@users.noreply.github.com> Date: Sat, 5 Sep 2020 18:26:00 +0200 Subject: [PATCH] CMake stuff, add Unix/Win32 ifs, add GLFW source --- CMakeLists.txt | 1 - PreLoad.cmake | 7 +++++++ lib/CMakeLists.txt | 6 ++++++ lib/glad/CMakeLists.txt | 4 +++- src/CMakeLists.txt | 2 +- src/Model.cpp | 2 +- src/Texture.cpp | 2 +- 7 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 PreLoad.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c73eeac..4a05266 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(Fall-Fever) set(OpenGL_GL_PREFERENCE "GLVND") -find_package(glfw3 3.3 REQUIRED) find_package(OpenGL REQUIRED) # Specify the C++ standard diff --git a/PreLoad.cmake b/PreLoad.cmake new file mode 100644 index 0000000..570a446 --- /dev/null +++ b/PreLoad.cmake @@ -0,0 +1,7 @@ +if(UNIX) + set(CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE) +endif(UNIX) + +if(WIN32) + set(CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE) +endif(WIN32) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4d98bfc..b792168 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,10 @@ +# Only build GLFW library +set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glad) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/stb) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glm) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/assimp) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glfw-3.3.2) diff --git a/lib/glad/CMakeLists.txt b/lib/glad/CMakeLists.txt index 799adf0..93b9a43 100644 --- a/lib/glad/CMakeLists.txt +++ b/lib/glad/CMakeLists.txt @@ -5,4 +5,6 @@ add_library( target_include_directories(glad PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(glad dl) +if(UNIX) + target_link_libraries(glad dl) +endif(UNIX) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 69ad5be..c5cddd2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,9 +13,9 @@ add_executable(Fall-Fever target_link_libraries( Fall-Fever PRIVATE - glfw glad stb + glfw ${OPENGL_LIBRARIES} assimp ) diff --git a/src/Model.cpp b/src/Model.cpp index f19bfd8..3e7ac3c 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -94,7 +94,7 @@ Mesh Model::processMesh(aiMesh *mesh, const aiScene *scene) { } // Material - if(mesh->mMaterialIndex >= 0) { + if(mesh->mMaterialIndex > 0) { aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex]; std::vector diffuseMaps = loadMaterialTextures(material, aiTextureType_DIFFUSE, texture_diffuse); textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end()); diff --git a/src/Texture.cpp b/src/Texture.cpp index 21378ef..c76cde0 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -9,7 +9,7 @@ Texture::Texture(const char* texturePath, uint8_t textureType) { this->textureType = textureType; stbi_set_flip_vertically_on_load(1); - auto *textureBuffer = stbi_load(texturePath, &textureWidth, &textureHeight, &bitsPerPixel, 4); + auto *textureBuffer = stbi_load(texturePath, &textureWidth, &textureHeight, &bitsPerPixel, STBI_rgb_alpha); // Push texture to grahics card; glGenTextures(1, &textureId);