From 7ca5b88ce32a7b788f9465ea8122958fd5815453 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 12 Sep 2013 22:45:43 +0200 Subject: [PATCH] Fix compilation errors on Mac OS X and remove the compilation of freeglut from the CMake files --- CMakeLists.txt | 4 +- cmake/FindFreeglut.cmake | 32 +++++++++ examples/collisionshapes/Scene.cpp | 4 +- examples/common/Box.cpp | 5 -- examples/common/Box.h | 9 ++- .../common/opengl-framework/CMakeLists.txt | 33 ++++++++-- .../opengl-framework/cmake/FindFREEGLUT.cmake | 32 +++++++++ .../opengl-framework/cmake/FindGLEW.cmake | 65 +++++++++++++++++++ examples/cubes/Scene.cpp | 7 +- examples/cubes/Scene.h | 3 - examples/joints/Scene.cpp | 4 +- src/collision/shapes/CollisionShape.h | 1 + src/memory/MemoryAllocator.h | 1 + 13 files changed, 173 insertions(+), 27 deletions(-) create mode 100644 cmake/FindFreeglut.cmake create mode 100644 examples/common/opengl-framework/cmake/FindFREEGLUT.cmake create mode 100644 examples/common/opengl-framework/cmake/FindGLEW.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 805fb5d3..ff4ecfaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ PROJECT(REACTPHYSICS3D) # Where to build the library SET(LIBRARY_OUTPUT_PATH lib/) -# Where to find the module to find special packages/libraries -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +# Where to build the executables +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) # Options OPTION(COMPILE_EXAMPLES "Select this if you want to build the examples" OFF) diff --git a/cmake/FindFreeglut.cmake b/cmake/FindFreeglut.cmake new file mode 100644 index 00000000..c8ea9d3e --- /dev/null +++ b/cmake/FindFreeglut.cmake @@ -0,0 +1,32 @@ +# This module is used to try to find the Freeglut library and include files + +IF(WIN32) + FIND_PATH(FREEGLUT_INCLUDE_DIR NAMES GL/freeglut.h) + FIND_LIBRARY(FREEGLUT_LIBRARY NAMES freeglut freeglut_static) + PATHS ${OPENGL_LIBRARY_DIR}) +ELSE(WIN32) + + IF(APPLE) + # Do nothing, we do not want to use freeglut on Mac OS X + ELSE(APPLE) + FIND_PATH(FREEGLUT_INCLUDE_DIR GL/freeglut.h /usr/include/GL + /usr/openwin/share/include + /usr/openwin/include + /opt/graphics/OpenGL/include + /opt/graphics/OpenGL/contrib/libglut) + + FIND_LIBRARY(FREEGLUT_LIBRARY NAMES freeglut freeglut_static PATHS /usr/openwin/lib) + FIND_LIBRARY(Xi_LIBRARY Xi /usr/openwin/lib) + FIND_LIBRARY(Xmu_LIBRARY Xmu /usr/openwin/lib) + ENDIF(APPLE) +ENDIF(WIN32) + +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEGLUT REQUIRED_VARS FREEGLUT_LIBRARY FREEGLUT_INCLUDE_DIR) + +IF(FREEGLUT_FOUND) + SET(FREEGLUT_LIBRARIES ${FREEGLUT_LIBRARY} ${Xi_LIBRARY} ${Xmu_LIBRARY}) + SET(FREEGLUT_LIBRARY ${FREEGLUT_LIBRARIES}) +ENDIF(FREEGLUT_FOUND) + +MARK_AS_ADVANCED(FREEGLUT_INCLUDE_DIR FREEGLUT_LIBRARY Xi_LIBRARY Xmu_LIBRARY) diff --git a/examples/collisionshapes/Scene.cpp b/examples/collisionshapes/Scene.cpp index 038567a9..923e4206 100644 --- a/examples/collisionshapes/Scene.cpp +++ b/examples/collisionshapes/Scene.cpp @@ -400,8 +400,8 @@ void Scene::render() { mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix()); mPhongShader.setVector3Uniform("light0PosCameraSpace", worldToCameraMatrix * mLight0.getOrigin()); mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f)); - Color& diffColLight0 = mLight0.getDiffuseColor(); - Color& specColLight0 = mLight0.getSpecularColor(); + const Color& diffColLight0 = mLight0.getDiffuseColor(); + const Color& specColLight0 = mLight0.getSpecularColor(); mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffColLight0.r, diffColLight0.g, diffColLight0.b)); mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specColLight0.r, specColLight0.g, specColLight0.b)); mPhongShader.setFloatUniform("shininess", 200.0f); diff --git a/examples/common/Box.cpp b/examples/common/Box.cpp index 757a3127..a148921b 100644 --- a/examples/common/Box.cpp +++ b/examples/common/Box.cpp @@ -157,11 +157,6 @@ void Box::render(openglframework::Shader& shader, shader.unbind(); } -// Set the color of the box -void Box::setColor(openglframework::Color& color) { - mColor = color; -} - // Update the transform matrix of the box void Box::updateTransform() { diff --git a/examples/common/Box.h b/examples/common/Box.h index c507ed4c..e89368a2 100644 --- a/examples/common/Box.h +++ b/examples/common/Box.h @@ -74,7 +74,7 @@ class Box : public openglframework::Object3D { /// True if the VBOs have already been created static bool areVBOsCreated; - // TODO : REMOVE THIS + /// Main color of the box openglframework::Color mColor; // -------------------- Methods -------------------- // @@ -103,7 +103,7 @@ class Box : public openglframework::Object3D { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix); /// Set the color of the box - void setColor(openglframework::Color& color); + void setColor(const openglframework::Color& color); }; // Return a pointer to the rigid body of the box @@ -111,4 +111,9 @@ inline rp3d::RigidBody* Box::getRigidBody() { return mRigidBody; } +// Set the color of the box +inline void Box::setColor(const openglframework::Color& color) { + mColor = color; +} + #endif diff --git a/examples/common/opengl-framework/CMakeLists.txt b/examples/common/opengl-framework/CMakeLists.txt index 7683a289..383c87a6 100644 --- a/examples/common/opengl-framework/CMakeLists.txt +++ b/examples/common/opengl-framework/CMakeLists.txt @@ -8,7 +8,7 @@ PROJECT(OPENGLFRAMEWORK) OPTION(USE_JPEG_TEXTURES "Select this if you want to use jpeg textures (libjpeg required)" OFF) # Where to find the module to find special packages/libraries -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") # Find OpenGL FIND_PACKAGE(OpenGL REQUIRED) @@ -26,6 +26,30 @@ else() MESSAGE("GLEW not found") endif() +# Find the GLUT/FREEGLUT library +IF(APPLE) + + # Find the GLUT library + FIND_PACKAGE(GLUT REQUIRED) + IF(GLUT_FOUND) + MESSAGE("GLUT found") + ELSE(GLUT_FOUND) + MESSAGE(SEND_ERROR "GLUT not found") + ENDIF(GLUT_FOUND) + +ELSE(APPLE) + + # Find the FREEGLUT library + FIND_PACKAGE(FREEGLUT REQUIRED) + IF(FREEGLUT_FOUND) + MESSAGE("FREEGLUT found") + ADD_DEFINITIONS(-DUSE_FREEGLUT) + ELSE(FREEGLUT_FOUND) + MESSAGE(SEND_ERROR "FREEGLUT not found") + ENDIF(FREEGLUT_FOUND) + +ENDIF(APPLE) + # If the user wants to use JPEG textures if(USE_JPEG_TEXTURES) @@ -38,11 +62,8 @@ if(USE_JPEG_TEXTURES) endif() endif() -# Freeglut -add_subdirectory(freeglut) - # Headers -INCLUDE_DIRECTORIES(src freeglut ${JPEG_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(src ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_PATH} ${FREEGLUT_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} ${JPEG_INCLUDE_DIR}) if(USE_JPEG_TEXTURES) add_definitions(-DUSE_JPEG_TEXTURE) @@ -62,4 +83,4 @@ ADD_LIBRARY ( ${OPENGLFRAMEWORK_SOURCES_FILES} ) -TARGET_LINK_LIBRARIES(openglframework ${GLEW_LIBRARIES} ${OPENGL_LIBRARY} freeglut_static) +TARGET_LINK_LIBRARIES(openglframework ${GLEW_LIBRARIES} ${OPENGL_LIBRARY} ${FREEGLUT_LIBRARY} ${GLUT_LIBRARY}) diff --git a/examples/common/opengl-framework/cmake/FindFREEGLUT.cmake b/examples/common/opengl-framework/cmake/FindFREEGLUT.cmake new file mode 100644 index 00000000..0ca4821e --- /dev/null +++ b/examples/common/opengl-framework/cmake/FindFREEGLUT.cmake @@ -0,0 +1,32 @@ +# This module is used to try to find the Freeglut library and include files + +IF(WIN32) + FIND_PATH(FREEGLUT_INCLUDE_DIR NAMES GL/freeglut.h) + FIND_LIBRARY(FREEGLUT_LIBRARY NAMES freeglut freeglut_static + PATHS ${OPENGL_LIBRARY_DIR}) +ELSE(WIN32) + + IF(APPLE) + # Do nothing, we do not want to use freeglut on Mac OS X + ELSE(APPLE) + FIND_PATH(FREEGLUT_INCLUDE_DIR GL/freeglut.h /usr/include/GL + /usr/openwin/share/include + /usr/openwin/include + /opt/graphics/OpenGL/include + /opt/graphics/OpenGL/contrib/libglut) + + FIND_LIBRARY(FREEGLUT_LIBRARY NAMES glut freeglut freeglut_static PATHS /usr/openwin/lib) + FIND_LIBRARY(Xi_LIBRARY Xi /usr/openwin/lib) + FIND_LIBRARY(Xmu_LIBRARY Xmu /usr/openwin/lib) + ENDIF(APPLE) +ENDIF(WIN32) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FREEGLUT REQUIRED_VARS FREEGLUT_LIBRARY FREEGLUT_INCLUDE_DIR) + +IF(FREEGLUT_FOUND) + SET(FREEGLUT_LIBRARIES ${FREEGLUT_LIBRARY} ${Xi_LIBRARY} ${Xmu_LIBRARY}) + SET(FREEGLUT_LIBRARY ${FREEGLUT_LIBRARIES}) +ENDIF(FREEGLUT_FOUND) + +MARK_AS_ADVANCED(FREEGLUT_INCLUDE_DIR FREEGLUT_LIBRARY Xi_LIBRARY Xmu_LIBRARY) diff --git a/examples/common/opengl-framework/cmake/FindGLEW.cmake b/examples/common/opengl-framework/cmake/FindGLEW.cmake new file mode 100644 index 00000000..c29c4eb2 --- /dev/null +++ b/examples/common/opengl-framework/cmake/FindGLEW.cmake @@ -0,0 +1,65 @@ +# +# Try to find GLEW library and include path. +# Once done this will define +# +# GLEW_FOUND +# GLEW_INCLUDE_PATH +# GLEW_LIBRARY +# + +IF (WIN32) +FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h +$ENV{PROGRAMFILES}/GLEW/include +${GLEW_ROOT_DIR}/include +DOC "The directory where GL/glew.h resides") + +IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64") +FIND_LIBRARY( GLEW_LIBRARY +NAMES glew64 glew64s +PATHS +$ENV{PROGRAMFILES}/GLEW/lib +${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin +${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib +DOC "The GLEW library (64-bit)" +) +ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64") +FIND_LIBRARY( GLEW_LIBRARY +NAMES glew GLEW glew32 glew32s +PATHS +$ENV{PROGRAMFILES}/GLEW/lib +${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin +${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib +DOC "The GLEW library" +) +ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64") +ELSE (WIN32) +FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h +/usr/include +/usr/local/include +/sw/include +/opt/local/include +${GLEW_ROOT_DIR}/include +DOC "The directory where GL/glew.h resides") + +FIND_LIBRARY( GLEW_LIBRARY +NAMES GLEW glew +PATHS +/usr/lib64 +/usr/lib +/usr/local/lib64 +/usr/local/lib +/sw/lib +/opt/local/lib +${GLEW_ROOT_DIR}/lib +DOC "The GLEW library") +ENDIF (WIN32) + +SET(GLEW_FOUND "NO") +IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY) +SET(GLEW_LIBRARIES ${GLEW_LIBRARY}) +SET(GLEW_FOUND "YES") +ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH) \ No newline at end of file diff --git a/examples/cubes/Scene.cpp b/examples/cubes/Scene.cpp index 6fc35f68..e3bc109a 100644 --- a/examples/cubes/Scene.cpp +++ b/examples/cubes/Scene.cpp @@ -71,7 +71,6 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0), Box* cube = new Box(BOX_SIZE, position , BOX_MASS, mDynamicsWorld); cube->getRigidBody()->setIsMotionEnabled(true); - mMapBodyToBox.insert(std::make_pair(cube->getRigidBody(), cube)); // Change the material properties of the rigid body rp3d::Material& material = cube->getRigidBody()->getMaterial(); @@ -88,8 +87,6 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0), // The floor must be a non-moving rigid body mFloor->getRigidBody()->setIsMotionEnabled(false); - mMapBodyToBox.insert(std::make_pair(mFloor->getRigidBody(), mFloor)); - // Change the material properties of the floor rigid body rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); material.setBounciness(rp3d::decimal(0.3)); @@ -175,8 +172,8 @@ void Scene::render() { mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix()); mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin()); mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f)); - Color& diffCol = mLight0.getDiffuseColor(); - Color& specCol = mLight0.getSpecularColor(); + const Color& diffCol = mLight0.getDiffuseColor(); + const Color& specCol = mLight0.getSpecularColor(); mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b)); mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b)); mPhongShader.setFloatUniform("shininess", 60.0f); diff --git a/examples/cubes/Scene.h b/examples/cubes/Scene.h index ed2033ef..a2802043 100644 --- a/examples/cubes/Scene.h +++ b/examples/cubes/Scene.h @@ -66,9 +66,6 @@ class Scene { /// True if the physics simulation is running bool mIsRunning; - // TODO : REMOVE THIS - std::map mMapBodyToBox; - public: // -------------------- Methods -------------------- // diff --git a/examples/joints/Scene.cpp b/examples/joints/Scene.cpp index b7b44159..5a566f17 100644 --- a/examples/joints/Scene.cpp +++ b/examples/joints/Scene.cpp @@ -166,8 +166,8 @@ void Scene::render() { mPhongShader.setVector3Uniform("light0PosCameraSpace",worldToCameraMatrix * mLight0.getOrigin()); mPhongShader.setMatrix4x4Uniform("projectionMatrix", camera.getProjectionMatrix()); mPhongShader.setVector3Uniform("lightAmbientColor", Vector3(0.3f, 0.3f, 0.3f)); - Color& diffCol = mLight0.getDiffuseColor(); - Color& specCol = mLight0.getSpecularColor(); + const Color& diffCol = mLight0.getDiffuseColor(); + const Color& specCol = mLight0.getSpecularColor(); mPhongShader.setVector3Uniform("light0DiffuseColor", Vector3(diffCol.r, diffCol.g, diffCol.b)); mPhongShader.setVector3Uniform("light0SpecularColor", Vector3(specCol.r, specCol.g, specCol.b)); mPhongShader.setFloatUniform("shininess", 60.0f); diff --git a/src/collision/shapes/CollisionShape.h b/src/collision/shapes/CollisionShape.h index 413015f8..4e6072c1 100644 --- a/src/collision/shapes/CollisionShape.h +++ b/src/collision/shapes/CollisionShape.h @@ -28,6 +28,7 @@ // Libraries #include +#include #include "../../mathematics/Vector3.h" #include "../../mathematics/Matrix3x3.h" #include "AABB.h" diff --git a/src/memory/MemoryAllocator.h b/src/memory/MemoryAllocator.h index 46caa3dd..23365949 100644 --- a/src/memory/MemoryAllocator.h +++ b/src/memory/MemoryAllocator.h @@ -27,6 +27,7 @@ #define REACTPHYSICS3D_MEMORY_ALLOCATOR_H // Libraries +#include #include "../configuration.h" /// ReactPhysics3D namespace