Skip to content

Commit

Permalink
fix compile errors on Linux
Browse files Browse the repository at this point in the history
On Linux, <sys/time.h> 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 openglredbook#3
	elmindreda openglredbook#5
  • Loading branch information
robotchaoX committed Mar 29, 2022
1 parent 253f197 commit e041ed1
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
3 changes: 3 additions & 0 deletions include/vapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define __VAPP_H__

#include "vgl.h"
#ifndef _WIN32
#include <sys/time.h>
#endif

class VermilionApplication
{
Expand Down
1 change: 1 addition & 0 deletions lib/vbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "vgl.h"

#include <stdio.h>
#include <string.h>

VBObject::VBObject(void)
: m_vao(0),
Expand Down
2 changes: 2 additions & 0 deletions lib/vdds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -641,6 +642,7 @@ void vglLoadDDS(const char* filename, vglImageData* image)
height >>= 1;
depth >>= 1;
}
}

done_close_file:
fclose(f);
Expand Down
1 change: 1 addition & 0 deletions src/10-fur/10-fur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

BEGIN_APP_DECLARATION(FurApplication)
// Override functions from base class
Expand Down
1 change: 1 addition & 0 deletions src/11-doublewrite/11-doublewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "LoadShaders.h"

#include <stdio.h>
#include <string.h>
#include <string>

#define MAX_FRAMEBUFFER_WIDTH 2048
Expand Down
1 change: 1 addition & 0 deletions src/11-oit/11-oit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "LoadShaders.h"

#include <stdio.h>
#include <string.h>
#include <string>

#define MAX_FRAMEBUFFER_WIDTH 2048
Expand Down
1 change: 1 addition & 0 deletions src/11-overdrawcount/11-overdrawcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "LoadShaders.h"

#include <stdio.h>
#include <string.h>
#include <string>

#define MAX_FRAMEBUFFER_WIDTH 2048
Expand Down
2 changes: 1 addition & 1 deletion src/12-particlesimulator/12-particlesimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e041ed1

Please sign in to comment.