From 6008d25bfc599da18c4b02a6e87397181d36fba6 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 1 Jun 2020 20:31:11 +0200 Subject: [PATCH] Fix build and compilation issues of the testbed application on Windows --- testbed/CMakeLists.txt | 38 +++++++++++--------- testbed/common/ConvexMesh.cpp | 2 +- testbed/opengl-framework/src/Camera.h | 6 ++-- testbed/opengl-framework/src/maths/Matrix4.h | 18 +++++----- testbed/scenes/cubes/CubesScene.h | 2 +- testbed/src/TestbedApplication.cpp | 13 +++++-- 6 files changed, 45 insertions(+), 34 deletions(-) mode change 100644 => 100755 testbed/common/ConvexMesh.cpp mode change 100644 => 100755 testbed/opengl-framework/src/Camera.h mode change 100644 => 100755 testbed/opengl-framework/src/maths/Matrix4.h mode change 100644 => 100755 testbed/src/TestbedApplication.cpp diff --git a/testbed/CMakeLists.txt b/testbed/CMakeLists.txt index cf3a5a8c..ffb813c5 100755 --- a/testbed/CMakeLists.txt +++ b/testbed/CMakeLists.txt @@ -11,20 +11,30 @@ set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE) # ---- Make sure to recursively clone all the git submodules for external libraries (nanogui) --- # find_package(Git QUIET) -if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") - # Update submodules as needed - option(CLONE_GIT_SUBMODULES "Check submodules during build" ON) - if(CLONE_GIT_SUBMODULES) - message(STATUS "Git Submodules update") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - RESULT_VARIABLE GIT_SUBMOD_RESULT) - if(NOT GIT_SUBMOD_RESULT EQUAL "0") - message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") - endif() +if(GIT_FOUND) + if (EXISTS "${CMAKE_SOURCE_DIR}/.git") + # Update submodules as needed + option(CLONE_GIT_SUBMODULES "Check submodules during build" ON) + if(CLONE_GIT_SUBMODULES) + message(STATUS "Git Submodules update") + message(STATUS "Working directory ${CMAKE_CURRENT_SOURCE_DIR}") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() + else() + message(FATAL_ERROR "This is not a Git repository. In order to build the testbed application, you need to clone the ReactPhysics3D repository.") endif() +else() + message(FATAL_ERROR "Git has not been found on your system. This is necessary to build the testbed application because git submodules command is used to get the testbed dependencies (nanogui library). You need to fill in the GIT_EXECUTABLE CMake variable with the path to the Git executable on your system to continue.") endif() +# Ask Nanogui not to build shared libraries +SET(NANOGUI_BUILD_SHARED OFF CACHE BOOL "Build Nanogui with static libraries" FORCE) + # Add the configurations from nanogui add_subdirectory(extern/nanogui) @@ -133,12 +143,6 @@ set(SCENES_SOURCES scenes/pile/PileScene.cpp ) -# Add .user file to set debug path in Visual Studio -set(USER_FILE testbed.vcxproj.user) -set(VS_USERFILE_WORKING_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH}) -set(OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${USER_FILE}) -configure_file(VisualStudioUserTemplate.user ${USER_FILE} @ONLY) - # Create the executable add_executable(testbed ${TESTBED_SOURCES} ${SCENES_SOURCES} ${COMMON_SOURCES} ${OPENGLFRAMEWORK_SOURCES}) diff --git a/testbed/common/ConvexMesh.cpp b/testbed/common/ConvexMesh.cpp old mode 100644 new mode 100755 index be91c09b..51120602 --- a/testbed/common/ConvexMesh.cpp +++ b/testbed/common/ConvexMesh.cpp @@ -39,7 +39,7 @@ ConvexMesh::ConvexMesh(bool createRigidBody, rp3d::PhysicsCommon& physicsCommon, // Polygon faces descriptions for the polyhedron mPolygonFaces = new rp3d::PolygonVertexArray::PolygonFace[getNbFaces(0)]; rp3d::PolygonVertexArray::PolygonFace* face = mPolygonFaces; - for (uint f=0; f < getNbFaces(0); f++) { + for (unsigned int f=0; f < getNbFaces(0); f++) { for (int v = 0; v < 3; v++) { diff --git a/testbed/opengl-framework/src/Camera.h b/testbed/opengl-framework/src/Camera.h old mode 100644 new mode 100755 index 108c363f..541ce9af --- a/testbed/opengl-framework/src/Camera.h +++ b/testbed/opengl-framework/src/Camera.h @@ -138,9 +138,9 @@ inline void Camera::setSceneRadius(float radius) { } // Set the clipping planes -inline void Camera::setClippingPlanes(float near, float far) { - mNearPlane = near; - mFarPlane = far; +inline void Camera::setClippingPlanes(float nearDistance, float farDistance) { + mNearPlane = nearDistance; + mFarPlane = farDistance; updateProjectionMatrix(); } diff --git a/testbed/opengl-framework/src/maths/Matrix4.h b/testbed/opengl-framework/src/maths/Matrix4.h old mode 100644 new mode 100755 index 1a504c38..84c4efc4 --- a/testbed/opengl-framework/src/maths/Matrix4.h +++ b/testbed/opengl-framework/src/maths/Matrix4.h @@ -436,21 +436,21 @@ inline Matrix4 Matrix4::rotationMatrix(const Vector3& axis, float angle) { } // Return a 4x4 perspective projection matrix -inline Matrix4 Matrix4::perspectiveProjectionMatrix(float near, float far, int width, int height, +inline Matrix4 Matrix4::perspectiveProjectionMatrix(float nearDistance, float farDistance, int width, int height, float fieldOfView) { // Compute the aspect ratio float aspect = float(width) / float(height); - float top = near * tan((fieldOfView / 2.0f) * (float(PI) / 180.0f)); + float top = nearDistance * tan((fieldOfView / 2.0f) * (float(PI) / 180.0f)); float bottom = -top; float left = bottom * aspect; float right = top * aspect; - float fx = 2.0f * near / (right - left); - float fy = 2.0f * near / (top - bottom); - float fz = -(far + near) / (far - near); - float fw = -2.0f * far * near / (far - near); + float fx = 2.0f * nearDistance / (right - left); + float fy = 2.0f * nearDistance / (top - bottom); + float fz = -(farDistance + nearDistance) / (farDistance - nearDistance); + float fw = -2.0f * farDistance * nearDistance / (farDistance - nearDistance); // Compute the projection matrix return Matrix4(fx, 0, 0, 0, @@ -460,7 +460,7 @@ inline Matrix4 Matrix4::perspectiveProjectionMatrix(float near, float far, int w } // Return a 4x4 orthographic projection matrix -inline Matrix4 Matrix4::orthoProjectionMatrix(float near, float far, int width, int height) { +inline Matrix4 Matrix4::orthoProjectionMatrix(float nearDistance, float farDistance, int width, int height) { // Compute the aspect ratio float aspect = float(width) / float(height); @@ -472,8 +472,8 @@ inline Matrix4 Matrix4::orthoProjectionMatrix(float near, float far, int width, float fx = 2.0f / (right - left); float fy = 2.0f / (top - bottom); - float fz = -2.0f / (far - near); - float fw = -(far + near) / (far - near); + float fz = -2.0f / (farDistance - nearDistance); + float fw = -(farDistance + nearDistance) / (farDistance - nearDistance); // Compute the projection matrix return Matrix4(fx, 0, 0, 0, diff --git a/testbed/scenes/cubes/CubesScene.h b/testbed/scenes/cubes/CubesScene.h index ae845452..dd012a70 100755 --- a/testbed/scenes/cubes/CubesScene.h +++ b/testbed/scenes/cubes/CubesScene.h @@ -53,7 +53,7 @@ class CubesScene : public SceneDemo { /// Box for the floor Box* mFloor; - uint iter; + unsigned int iter; public: diff --git a/testbed/src/TestbedApplication.cpp b/testbed/src/TestbedApplication.cpp old mode 100644 new mode 100755 index 8c0f9f6a..34ddab7f --- a/testbed/src/TestbedApplication.cpp +++ b/testbed/src/TestbedApplication.cpp @@ -91,9 +91,16 @@ void TestbedApplication::init() { mTimer.start(); - // Enable OpenGL error reporting - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback(onOpenGLError, 0); + int glMajorVersion, glMinorVersion; + glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion); + glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion); + + if (glMajorVersion > 4 || (glMajorVersion == 4 && glMinorVersion >= 3)) { + + // Enable OpenGL error reporting + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(onOpenGLError, 0); + } mIsInitialized = true; }