From 76deef43580dffd40c12b23f59ce0dde36d00192 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sun, 15 Sep 2013 23:32:42 +0200 Subject: [PATCH] Fix issues on Mac OS X --- CMakeLists.txt | 3 --- examples/collisionshapes/CMakeLists.txt | 7 +++++-- examples/collisionshapes/CollisionShapes.cpp | 9 ++++++++- examples/common/Viewer.cpp | 2 ++ examples/common/opengl-framework/src/GlutViewer.h | 6 +++++- .../common/opengl-framework/src/shaders/phong.frag | 7 +++---- examples/cubes/CMakeLists.txt | 5 ++++- examples/cubes/Cubes.cpp | 10 +++++++++- examples/joints/CMakeLists.txt | 5 ++++- examples/joints/Joints.cpp | 9 ++++++++- 10 files changed, 48 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4ecfaf..5613cb52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,6 @@ PROJECT(REACTPHYSICS3D) # Where to build the library SET(LIBRARY_OUTPUT_PATH lib/) -# 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) OPTION(COMPILE_TESTS "Select this if you want to build the tests" OFF) diff --git a/examples/collisionshapes/CMakeLists.txt b/examples/collisionshapes/CMakeLists.txt index 932b10e8..bb0d377d 100644 --- a/examples/collisionshapes/CMakeLists.txt +++ b/examples/collisionshapes/CMakeLists.txt @@ -4,11 +4,14 @@ cmake_minimum_required(VERSION 2.6) # Project configuration PROJECT(CollisionShapes) +# Where to build the executable +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/collisionshapes/) + # Copy the shaders used for the demo into the build directory -FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/shaders/") +FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/") # Copy the meshes used for the demo into the build directory -FILE(COPY "../common/meshes/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/meshes/") +FILE(COPY "../common/meshes/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/meshes/") # Headers INCLUDE_DIRECTORIES("../common/opengl-framework/src/" "../common/") diff --git a/examples/collisionshapes/CollisionShapes.cpp b/examples/collisionshapes/CollisionShapes.cpp index b444c466..cf1f9fdc 100644 --- a/examples/collisionshapes/CollisionShapes.cpp +++ b/examples/collisionshapes/CollisionShapes.cpp @@ -67,7 +67,11 @@ int main(int argc, char** argv) { glutMouseFunc(mouseButton); glutMotionFunc(mouseMotion); glutKeyboardFunc(keyboard); +#ifdef USE_FREEGLUT glutCloseFunc(finish); +#else + atexit(finish); +#endif // Glut main looop glutMainLoop(); @@ -115,7 +119,10 @@ void keyboard(unsigned char key, int x, int y) { // Escape key case 27: - glutLeaveMainLoop(); + #ifdef USE_FREEGLUT + // TODO : Check if we need to call finish() here + glutLeaveMainLoop(); + #endif break; // Space bar diff --git a/examples/common/Viewer.cpp b/examples/common/Viewer.cpp index e0114f00..1ff19ccc 100644 --- a/examples/common/Viewer.cpp +++ b/examples/common/Viewer.cpp @@ -68,6 +68,7 @@ void Viewer::displayGUI() { // Display the FPS void Viewer::displayFPS() { +#ifdef USE_FREEGLUT glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, mCamera.getWidth(), mCamera.getHeight(), 0, -1, 1); @@ -80,4 +81,5 @@ void Viewer::displayFPS() { std::stringstream ss; ss << "FPS : " << fps; glutBitmapString(GLUT_BITMAP_HELVETICA_12, (const unsigned char*)ss.str().c_str()); +#endif } diff --git a/examples/common/opengl-framework/src/GlutViewer.h b/examples/common/opengl-framework/src/GlutViewer.h index 7718a1af..3d6d3c56 100644 --- a/examples/common/opengl-framework/src/GlutViewer.h +++ b/examples/common/opengl-framework/src/GlutViewer.h @@ -32,7 +32,11 @@ #include "maths/Vector2.h" #include #include -#include "GL/freeglut.h" +#ifdef __APPLE__ + #include "GLUT/glut.h" +#else + #include "GL/freeglut.h" +#endif namespace openglframework { diff --git a/examples/common/opengl-framework/src/shaders/phong.frag b/examples/common/opengl-framework/src/shaders/phong.frag index 009c5cc7..f09777da 100644 --- a/examples/common/opengl-framework/src/shaders/phong.frag +++ b/examples/common/opengl-framework/src/shaders/phong.frag @@ -41,8 +41,7 @@ varying vec2 texCoords; // Texture coordinates void main() { // Compute the ambient term - //vec3 ambient = lightAmbientColor; - vec3 ambient = vertexColor.rgb + 0.0 * lightAmbientColor; + vec3 ambient = lightAmbientColor; // Get the texture color vec3 textureColor = vertexColor.rgb; @@ -59,8 +58,8 @@ void main() { // Compute the specular term of light 0 vec3 V = normalize(-vertexPosCameraSpace); vec3 H0 = normalize(V + L0); - float specularFactor = pow(max(dot(N, H0), 0), shininess); - if (diffuseFactor < 0) specularFactor = 0.0; + float specularFactor = pow(max(dot(N, H0), 0.0), shininess); + if (diffuseFactor < 0.0) specularFactor = 0.0; vec3 specular = light0SpecularColor * specularFactor; // Compute the final color diff --git a/examples/cubes/CMakeLists.txt b/examples/cubes/CMakeLists.txt index f65c428a..90f64abb 100644 --- a/examples/cubes/CMakeLists.txt +++ b/examples/cubes/CMakeLists.txt @@ -4,8 +4,11 @@ cmake_minimum_required(VERSION 2.6) # Project configuration PROJECT(Cubes) +# Where to build the executable +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/cubes/) + # Copy the shaders used for the demo into the build directory -FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/shaders/") +FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/") # Headers INCLUDE_DIRECTORIES("../common/opengl-framework/src/" "../common/") diff --git a/examples/cubes/Cubes.cpp b/examples/cubes/Cubes.cpp index e0dc6ad0..80c5d501 100644 --- a/examples/cubes/Cubes.cpp +++ b/examples/cubes/Cubes.cpp @@ -66,7 +66,12 @@ int main(int argc, char** argv) { glutMouseFunc(mouseButton); glutMotionFunc(mouseMotion); glutKeyboardFunc(keyboard); + +#ifdef USE_FREEGLUT glutCloseFunc(finish); +#else + atexit(finish); +#endif // Glut main looop glutMainLoop(); @@ -114,7 +119,10 @@ void keyboard(unsigned char key, int x, int y) { // Escape key case 27: - glutLeaveMainLoop(); + #ifdef USE_FREEGLUT + // TODO : Check if we need to call finish() here + glutLeaveMainLoop(); + #endif break; // Space bar diff --git a/examples/joints/CMakeLists.txt b/examples/joints/CMakeLists.txt index dc2eed0c..458a9731 100644 --- a/examples/joints/CMakeLists.txt +++ b/examples/joints/CMakeLists.txt @@ -4,8 +4,11 @@ cmake_minimum_required(VERSION 2.6) # Project configuration PROJECT(Joints) +# Where to build the executable +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/joints/) + # Copy the shaders used for the demo into the build directory -FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/shaders/") +FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${EXECUTABLE_OUTPUT_PATH}/shaders/") # Headers INCLUDE_DIRECTORIES("../common/opengl-framework/src/" "../common/") diff --git a/examples/joints/Joints.cpp b/examples/joints/Joints.cpp index f42ffb97..75c6892a 100644 --- a/examples/joints/Joints.cpp +++ b/examples/joints/Joints.cpp @@ -66,7 +66,11 @@ int main(int argc, char** argv) { glutMouseFunc(mouseButton); glutMotionFunc(mouseMotion); glutKeyboardFunc(keyboard); +#ifdef USE_FREEGLUT glutCloseFunc(finish); +#else + atexit(finish); +#endif // Glut main looop glutMainLoop(); @@ -114,7 +118,10 @@ void keyboard(unsigned char key, int x, int y) { // Escape key case 27: - glutLeaveMainLoop(); + #ifdef USE_FREEGLUT + // TODO : Check if we need to call finish() here + glutLeaveMainLoop(); + #endif break; // Space bar