Fix compilation errors on Mac OS X and remove the compilation of freeglut from the CMake files

This commit is contained in:
Daniel Chappuis 2013-09-12 22:45:43 +02:00
parent f575a46fdd
commit 7ca5b88ce3
13 changed files with 173 additions and 27 deletions

View File

@ -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)

32
cmake/FindFreeglut.cmake Normal file
View File

@ -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)

View File

@ -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);

View File

@ -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() {

View File

@ -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

View File

@ -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})

View File

@ -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)

View File

@ -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)

View File

@ -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<rp3d::RigidBody*, Box*>(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<rp3d::RigidBody*, Box*>(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);

View File

@ -66,9 +66,6 @@ class Scene {
/// True if the physics simulation is running
bool mIsRunning;
// TODO : REMOVE THIS
std::map<rp3d::RigidBody*, Box*> mMapBodyToBox;
public:
// -------------------- Methods -------------------- //

View File

@ -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);

View File

@ -28,6 +28,7 @@
// Libraries
#include <cassert>
#include <typeinfo>
#include "../../mathematics/Vector3.h"
#include "../../mathematics/Matrix3x3.h"
#include "AABB.h"

View File

@ -27,6 +27,7 @@
#define REACTPHYSICS3D_MEMORY_ALLOCATOR_H
// Libraries
#include <cstring>
#include "../configuration.h"
/// ReactPhysics3D namespace