Fix build and compilation issues of the testbed application on Windows

This commit is contained in:
Daniel Chappuis 2020-06-01 20:31:11 +02:00
parent bdc3153f55
commit 6008d25bfc
6 changed files with 45 additions and 34 deletions

View File

@ -11,20 +11,30 @@ set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE)
# ---- Make sure to recursively clone all the git submodules for external libraries (nanogui) --- # # ---- Make sure to recursively clone all the git submodules for external libraries (nanogui) --- #
find_package(Git QUIET) find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") if(GIT_FOUND)
# Update submodules as needed if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
option(CLONE_GIT_SUBMODULES "Check submodules during build" ON) # Update submodules as needed
if(CLONE_GIT_SUBMODULES) option(CLONE_GIT_SUBMODULES "Check submodules during build" ON)
message(STATUS "Git Submodules update") if(CLONE_GIT_SUBMODULES)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive message(STATUS "Git Submodules update")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} message(STATUS "Working directory ${CMAKE_CURRENT_SOURCE_DIR}")
RESULT_VARIABLE GIT_SUBMOD_RESULT) execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
if(NOT GIT_SUBMOD_RESULT EQUAL "0") WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") RESULT_VARIABLE GIT_SUBMOD_RESULT)
endif() 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() 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() 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 the configurations from nanogui
add_subdirectory(extern/nanogui) add_subdirectory(extern/nanogui)
@ -133,12 +143,6 @@ set(SCENES_SOURCES
scenes/pile/PileScene.cpp 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 # Create the executable
add_executable(testbed ${TESTBED_SOURCES} ${SCENES_SOURCES} ${COMMON_SOURCES} ${OPENGLFRAMEWORK_SOURCES}) add_executable(testbed ${TESTBED_SOURCES} ${SCENES_SOURCES} ${COMMON_SOURCES} ${OPENGLFRAMEWORK_SOURCES})

2
testbed/common/ConvexMesh.cpp Normal file → Executable file
View File

@ -39,7 +39,7 @@ ConvexMesh::ConvexMesh(bool createRigidBody, rp3d::PhysicsCommon& physicsCommon,
// Polygon faces descriptions for the polyhedron // Polygon faces descriptions for the polyhedron
mPolygonFaces = new rp3d::PolygonVertexArray::PolygonFace[getNbFaces(0)]; mPolygonFaces = new rp3d::PolygonVertexArray::PolygonFace[getNbFaces(0)];
rp3d::PolygonVertexArray::PolygonFace* face = mPolygonFaces; 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++) { for (int v = 0; v < 3; v++) {

6
testbed/opengl-framework/src/Camera.h Normal file → Executable file
View File

@ -138,9 +138,9 @@ inline void Camera::setSceneRadius(float radius) {
} }
// Set the clipping planes // Set the clipping planes
inline void Camera::setClippingPlanes(float near, float far) { inline void Camera::setClippingPlanes(float nearDistance, float farDistance) {
mNearPlane = near; mNearPlane = nearDistance;
mFarPlane = far; mFarPlane = farDistance;
updateProjectionMatrix(); updateProjectionMatrix();
} }

18
testbed/opengl-framework/src/maths/Matrix4.h Normal file → Executable file
View File

@ -436,21 +436,21 @@ inline Matrix4 Matrix4::rotationMatrix(const Vector3& axis, float angle) {
} }
// Return a 4x4 perspective projection matrix // 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) { float fieldOfView) {
// Compute the aspect ratio // Compute the aspect ratio
float aspect = float(width) / float(height); 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 bottom = -top;
float left = bottom * aspect; float left = bottom * aspect;
float right = top * aspect; float right = top * aspect;
float fx = 2.0f * near / (right - left); float fx = 2.0f * nearDistance / (right - left);
float fy = 2.0f * near / (top - bottom); float fy = 2.0f * nearDistance / (top - bottom);
float fz = -(far + near) / (far - near); float fz = -(farDistance + nearDistance) / (farDistance - nearDistance);
float fw = -2.0f * far * near / (far - near); float fw = -2.0f * farDistance * nearDistance / (farDistance - nearDistance);
// Compute the projection matrix // Compute the projection matrix
return Matrix4(fx, 0, 0, 0, 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 // 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 // Compute the aspect ratio
float aspect = float(width) / float(height); 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 fx = 2.0f / (right - left);
float fy = 2.0f / (top - bottom); float fy = 2.0f / (top - bottom);
float fz = -2.0f / (far - near); float fz = -2.0f / (farDistance - nearDistance);
float fw = -(far + near) / (far - near); float fw = -(farDistance + nearDistance) / (farDistance - nearDistance);
// Compute the projection matrix // Compute the projection matrix
return Matrix4(fx, 0, 0, 0, return Matrix4(fx, 0, 0, 0,

View File

@ -53,7 +53,7 @@ class CubesScene : public SceneDemo {
/// Box for the floor /// Box for the floor
Box* mFloor; Box* mFloor;
uint iter; unsigned int iter;
public: public:

13
testbed/src/TestbedApplication.cpp Normal file → Executable file
View File

@ -91,9 +91,16 @@ void TestbedApplication::init() {
mTimer.start(); mTimer.start();
// Enable OpenGL error reporting int glMajorVersion, glMinorVersion;
glEnable(GL_DEBUG_OUTPUT); glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion);
glDebugMessageCallback(onOpenGLError, 0); 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; mIsInitialized = true;
} }