From e041ed1cbee9aa89fe3cb11ae93be89303ef8ee2 Mon Sep 17 00:00:00 2001 From: robotchaoX Date: Thu, 24 Mar 2022 16:14:35 +0800 Subject: [PATCH] fix compile errors on Linux On Linux, must be included to make struct timeval known. string.h must be included to use memset(). A jump to a label (done_close_file) must not cross local declarations. The corresponding code has been encapsulated in a block. The use of the STRINGIZE macro leads to an error where the compiler sees the #version 430 sequence as an invalid preprocessor directive. Move add_subdirectory(lib/glfw) before examples compile in CmakeList.txt to avoid build dependence error. Reference: jhannemann https://github.com/openglredbook/examples/pull/3 elmindreda https://github.com/openglredbook/examples/pull/5 --- CMakeLists.txt | 4 ++-- include/vapp.h | 3 +++ lib/vbm.cpp | 1 + lib/vdds.cpp | 2 ++ src/10-fur/10-fur.cpp | 1 + src/11-doublewrite/11-doublewrite.cpp | 1 + src/11-oit/11-oit.cpp | 1 + src/11-overdrawcount/11-overdrawcount.cpp | 1 + src/12-particlesimulator/12-particlesimulator.cpp | 2 +- 9 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05f3354..4e16883 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ set (CMAKE_DEBUG_POSTFIX "_d") find_package(OpenGL REQUIRED) +add_subdirectory(lib/glfw) + if(WIN32) set(COMMON_LIBS vermilion ${OPENGL_LIBRARIES} optimized glfw3 debug glfw3_d) elseif (UNIX) @@ -101,7 +103,5 @@ ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") include_directories( include ) include_directories(lib/glfw/include) -add_subdirectory(lib/glfw) - ADD_CUSTOM_TARGET(debug ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR}) ADD_CUSTOM_TARGET(release ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Release ${PROJECT_SOURCE_DIR}) diff --git a/include/vapp.h b/include/vapp.h index 7796052..0939534 100644 --- a/include/vapp.h +++ b/include/vapp.h @@ -2,6 +2,9 @@ #define __VAPP_H__ #include "vgl.h" +#ifndef _WIN32 +#include +#endif class VermilionApplication { diff --git a/lib/vbm.cpp b/lib/vbm.cpp index 22f3968..aafd613 100644 --- a/lib/vbm.cpp +++ b/lib/vbm.cpp @@ -4,6 +4,7 @@ #include "vgl.h" #include +#include VBObject::VBObject(void) : m_vao(0), diff --git a/lib/vdds.cpp b/lib/vdds.cpp index e417679..eeda995 100644 --- a/lib/vdds.cpp +++ b/lib/vdds.cpp @@ -603,6 +603,7 @@ void vglLoadDDS(const char* filename, vglImageData* image) if (image->target == GL_NONE) goto done_close_file; +{ size_t current_pos = ftell(f); size_t file_size; fseek(f, 0, SEEK_END); @@ -641,6 +642,7 @@ void vglLoadDDS(const char* filename, vglImageData* image) height >>= 1; depth >>= 1; } +} done_close_file: fclose(f); diff --git a/src/10-fur/10-fur.cpp b/src/10-fur/10-fur.cpp index d9ce31a..b478f4a 100644 --- a/src/10-fur/10-fur.cpp +++ b/src/10-fur/10-fur.cpp @@ -13,6 +13,7 @@ #include #include +#include BEGIN_APP_DECLARATION(FurApplication) // Override functions from base class diff --git a/src/11-doublewrite/11-doublewrite.cpp b/src/11-doublewrite/11-doublewrite.cpp index 0ad0f60..d637ef7 100644 --- a/src/11-doublewrite/11-doublewrite.cpp +++ b/src/11-doublewrite/11-doublewrite.cpp @@ -14,6 +14,7 @@ #include "LoadShaders.h" #include +#include #include #define MAX_FRAMEBUFFER_WIDTH 2048 diff --git a/src/11-oit/11-oit.cpp b/src/11-oit/11-oit.cpp index 20fd8cc..aa626cb 100644 --- a/src/11-oit/11-oit.cpp +++ b/src/11-oit/11-oit.cpp @@ -14,6 +14,7 @@ #include "LoadShaders.h" #include +#include #include #define MAX_FRAMEBUFFER_WIDTH 2048 diff --git a/src/11-overdrawcount/11-overdrawcount.cpp b/src/11-overdrawcount/11-overdrawcount.cpp index 2666377..dffec53 100644 --- a/src/11-overdrawcount/11-overdrawcount.cpp +++ b/src/11-overdrawcount/11-overdrawcount.cpp @@ -14,6 +14,7 @@ #include "LoadShaders.h" #include +#include #include #define MAX_FRAMEBUFFER_WIDTH 2048 diff --git a/src/12-particlesimulator/12-particlesimulator.cpp b/src/12-particlesimulator/12-particlesimulator.cpp index ea90b5e..1fbf282 100644 --- a/src/12-particlesimulator/12-particlesimulator.cpp +++ b/src/12-particlesimulator/12-particlesimulator.cpp @@ -110,7 +110,7 @@ void ComputeParticleSimulator::Initialize(const char * title) compute_prog = glCreateProgram(); static const char compute_shader_source[] = - STRINGIZE( + STRINGIZE( \ #version 430 core\n layout (std140, binding = 0) uniform attractor_block