From 7b41af1765c26714c82edc94476e07f69ffaa152 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 19 Jan 2010 22:59:49 +0000 Subject: [PATCH] Don't use GLUT by default under Windows, but a Win32 App instead. All demos have to be fixed (only basic demo works now). Also on Mac OSX, we plan to use cocoa instead of Glut. --- CMakeLists.txt | 57 +++++++++++++++++----------- Demos/BasicDemo/BasicDemo.cpp | 5 ++- Demos/BasicDemo/BasicDemo.h | 10 ++++- Demos/BasicDemo/CMakeLists.txt | 31 +++++++++++---- Demos/CMakeLists.txt | 45 ++++++++++++---------- Demos/OpenGL/CMakeLists.txt | 21 +++++++++- Demos/OpenGL/GLDebugDrawer.cpp | 9 +---- Demos/OpenGL/GLDebugFont.cpp | 5 ++- Demos/OpenGL/GL_DialogWindow.h | 4 +- Demos/OpenGL/GlutDemoApplication.cpp | 2 + Demos/OpenGL/GlutStuff.cpp | 2 + Demos/OpenGL/GlutStuff.h | 11 ++++-- Demos/OpenGL/Win32AppMain.cpp | 34 ++++++++++++++--- 13 files changed, 161 insertions(+), 75 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c59db3e..4bfc5aac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,18 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Release") ENDIF (NOT CMAKE_BUILD_TYPE) -# string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) -remove_definitions(-D_WINDOWS ) + + +IF (WIN32) +OPTION(USE_GLUT "Use Glut" OFF) +ELSE(WIN32) +OPTION(USE_GLUT "Use Glut" ON) +ENDIF(WIN32) + +IF (USE_GLUT) + string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + remove_definitions(-D_WINDOWS ) +ENDIF (USE_GLUT) IF(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) @@ -33,31 +43,32 @@ ENDIF (OPENGL_FOUND) FIND_PACKAGE(GLU) -FIND_PACKAGE(GLUT) -IF (GLUT_FOUND) -MESSAGE("GLUT FOUND") -MESSAGE(${GLUT_glut_LIBRARY}) -ELSE (GLUT_FOUND) +IF (USE_GLUT) + FIND_PACKAGE(GLUT) + IF (GLUT_FOUND) + MESSAGE("GLUT FOUND") + MESSAGE(${GLUT_glut_LIBRARY}) + ELSE (GLUT_FOUND) -IF (MINGW) -MESSAGE ("GLUT NOT FOUND not found, trying to use MINGW glut32") -SET(GLUT_glut_LIBRARY glut32) -ENDIF (MINGW) + IF (MINGW) + MESSAGE ("GLUT NOT FOUND not found, trying to use MINGW glut32") + SET(GLUT_glut_LIBRARY glut32) + ENDIF (MINGW) -IF (MSVC) -MESSAGE ("GLUT NOT FOUND, trying to use Bullet/Glut/glut32.lib for MSVC") -SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib) -ENDIF (MSVC) -ENDIF (GLUT_FOUND) + IF (MSVC) + MESSAGE ("GLUT NOT FOUND, trying to use Bullet/Glut/glut32.lib for MSVC") + SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib) + ENDIF (MSVC) + ENDIF (GLUT_FOUND) + IF (WIN32) + INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut) + ELSE (WIN32) + # This is the lines for linux. This should always work if everything is installed and working fine. + INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR}) + ENDIF (WIN32) -IF (WIN32) - INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut) -ELSE (WIN32) - # This is the lines for linux. This should always work if everything is installed and working fine. - INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR}) -ENDIF (WIN32) - +ENDIF(USE_GLUT) OPTION(BUILD_DEMOS "Set when you want to build the demos" ON) IF(BUILD_DEMOS) diff --git a/Demos/BasicDemo/BasicDemo.cpp b/Demos/BasicDemo/BasicDemo.cpp index fd6223aac..9854daacf 100644 --- a/Demos/BasicDemo/BasicDemo.cpp +++ b/Demos/BasicDemo/BasicDemo.cpp @@ -14,6 +14,7 @@ subject to the following restrictions: */ + ///create 125 (5x5x5) dynamic object #define ARRAY_SIZE_X 5 #define ARRAY_SIZE_Y 5 @@ -54,7 +55,7 @@ void BasicDemo::clientMoveAndDisplay() glFlush(); - glutSwapBuffers(); + swapBuffers(); } @@ -71,7 +72,7 @@ void BasicDemo::displayCallback(void) { m_dynamicsWorld->debugDrawWorld(); glFlush(); - glutSwapBuffers(); + swapBuffers(); } diff --git a/Demos/BasicDemo/BasicDemo.h b/Demos/BasicDemo/BasicDemo.h index fbcec80ad..1fa9f1fbe 100644 --- a/Demos/BasicDemo/BasicDemo.h +++ b/Demos/BasicDemo/BasicDemo.h @@ -15,7 +15,14 @@ subject to the following restrictions: #ifndef BASIC_DEMO_H #define BASIC_DEMO_H +#ifdef _WINDOWS +#include "Win32DemoApplication.h" +#define PlatformDemoApplication Win32DemoApplication +#else #include "GlutDemoApplication.h" +#define PlatformDemoApplication GlutDemoApplication +#endif + #include "LinearMath/btAlignedObjectArray.h" class btBroadphaseInterface; @@ -27,7 +34,8 @@ struct btCollisionAlgorithmCreateFunc; class btDefaultCollisionConfiguration; ///BasicDemo is good starting point for learning the code base and porting. -class BasicDemo : public GlutDemoApplication + +class BasicDemo : public PlatformDemoApplication { //keep the collision shapes, for deletion/cleanup diff --git a/Demos/BasicDemo/CMakeLists.txt b/Demos/BasicDemo/CMakeLists.txt index 010dcf382..226c5c873 100644 --- a/Demos/BasicDemo/CMakeLists.txt +++ b/Demos/BasicDemo/CMakeLists.txt @@ -15,12 +15,29 @@ INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ) -LINK_LIBRARIES( -OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} -) -ADD_EXECUTABLE(AppBasicDemo - main.cpp - BasicDemo.cpp -) +IF (USE_GLUT) + LINK_LIBRARIES( + OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + + ADD_EXECUTABLE(AppBasicDemo + main.cpp + BasicDemo.cpp + BasicDemo.h + ) +ELSE (USE_GLUT) + + LINK_LIBRARIES( + OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + + ADD_EXECUTABLE(AppBasicDemo + WIN32 + ../OpenGL/Win32AppMain.cpp + Win32BasicDemo.cpp + BasicDemo.cpp + BasicDemo.h + ) +ENDIF (USE_GLUT) \ No newline at end of file diff --git a/Demos/CMakeLists.txt b/Demos/CMakeLists.txt index 77ec65d08..ba0588b79 100644 --- a/Demos/CMakeLists.txt +++ b/Demos/CMakeLists.txt @@ -1,20 +1,25 @@ -if (CMAKE_SIZEOF_VOID_P MATCHES "8") - SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld - CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo Raytracer - RagdollDemo ForkLiftDemo BasicDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo - ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo HeightFieldFluidDemo - CollisionInterfaceDemo ConcaveConvexcastDemo SimplexDemo DynamicControlDemo - DoublePrecisionDemo ConcaveDemo CollisionDemo - ContinuousConvexCollision ConcaveRaycastDemo GjkConvexCastDemo - MultiMaterialDemo) -else (CMAKE_SIZEOF_VOID_P MATCHES "8") - SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld - MultiThreadedDemo CcdPhysicsDemo ConstraintDemo SliderConstraintDemo Raytracer - GenericJointDemo RagdollDemo ForkLiftDemo BasicDemo Box2dDemo BspDemo MovingConcaveDemo - VehicleDemo ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo - HeightFieldFluidDemo - CollisionInterfaceDemo ConcaveConvexcastDemo SimplexDemo DynamicControlDemo - DoublePrecisionDemo ConcaveDemo CollisionDemo - ContinuousConvexCollision ConcaveRaycastDemo GjkConvexCastDemo - MultiMaterialDemo) -endif (CMAKE_SIZEOF_VOID_P MATCHES "8") +SUBDIRS( OpenGL BasicDemo ) + + +#todo: re-enable the rest of the demos again + +#if (CMAKE_SIZEOF_VOID_P MATCHES "8") +# SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld +# CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo Raytracer +# RagdollDemo ForkLiftDemo BasicDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo +# ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo HeightFieldFluidDemo +# CollisionInterfaceDemo ConcaveConvexcastDemo SimplexDemo DynamicControlDemo +# DoublePrecisionDemo ConcaveDemo CollisionDemo +# ContinuousConvexCollision ConcaveRaycastDemo GjkConvexCastDemo +# MultiMaterialDemo) +#else (CMAKE_SIZEOF_VOID_P MATCHES "8") +# SUBDIRS( OpenGL AllBulletDemos ConvexDecompositionDemo Benchmarks HelloWorld +# MultiThreadedDemo CcdPhysicsDemo ConstraintDemo SliderConstraintDemo Raytracer +# GenericJointDemo RagdollDemo ForkLiftDemo BasicDemo Box2dDemo BspDemo MovingConcaveDemo +# VehicleDemo ColladaDemo UserCollisionAlgorithm CharacterDemo SoftDemo +# HeightFieldFluidDemo +# CollisionInterfaceDemo ConcaveConvexcastDemo SimplexDemo DynamicControlDemo +# DoublePrecisionDemo ConcaveDemo CollisionDemo +# ContinuousConvexCollision ConcaveRaycastDemo GjkConvexCastDemo +# MultiMaterialDemo) +#endif (CMAKE_SIZEOF_VOID_P MATCHES "8") diff --git a/Demos/OpenGL/CMakeLists.txt b/Demos/OpenGL/CMakeLists.txt index 376cbeec6..95d69da76 100644 --- a/Demos/OpenGL/CMakeLists.txt +++ b/Demos/OpenGL/CMakeLists.txt @@ -12,24 +12,41 @@ - INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexHull ) + ADD_LIBRARY(OpenGLSupport GLDebugFont.cpp + GLDebugFont.h GL_DialogDynamicsWorld.cpp + GL_DialogDynamicsWorld.h GL_DialogWindow.cpp + GL_DialogWindow.h GL_ShapeDrawer.cpp + GL_ShapeDrawer.h GL_Simplex1to4.cpp + GL_Simplex1to4.h GLDebugDrawer.cpp - GlutStuff.cpp + GLDebugDrawer.h + RenderTexture.cpp + RenderTexture.h DemoApplication.cpp + DemoApplication.h + GlutDemoApplication.cpp + GlutDemoApplication.h + GlutStuff.cpp + GlutStuff.h + + + Win32DemoApplication.cpp + Win32DemoApplication.h ) + IF (BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES(OpenGLSupport BulletDynamics BulletCollision ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) ENDIF (BUILD_SHARED_LIBS) diff --git a/Demos/OpenGL/GLDebugDrawer.cpp b/Demos/OpenGL/GLDebugDrawer.cpp index 0c7d5c64a..0310d7cf8 100644 --- a/Demos/OpenGL/GLDebugDrawer.cpp +++ b/Demos/OpenGL/GLDebugDrawer.cpp @@ -24,14 +24,7 @@ void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btV void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color) { -// if (m_debugMode > 0) - { - glBegin(GL_LINES); - glColor4f(color.getX(), color.getY(), color.getZ(),1.f); - glVertex3d(from.getX(), from.getY(), from.getZ()); - glVertex3d(to.getX(), to.getY(), to.getZ()); - glEnd(); - } + drawLine(from,to,color,color); } void GLDebugDrawer::drawSphere (const btVector3& p, btScalar radius, const btVector3& color) diff --git a/Demos/OpenGL/GLDebugFont.cpp b/Demos/OpenGL/GLDebugFont.cpp index 233473aca..e6a7ab4ce 100644 --- a/Demos/OpenGL/GLDebugFont.cpp +++ b/Demos/OpenGL/GLDebugFont.cpp @@ -33,11 +33,14 @@ subject to the following restrictions: #endif #else -#include + + #ifdef _WINDOWS #include #include #include +#else +#include #endif #endif diff --git a/Demos/OpenGL/GL_DialogWindow.h b/Demos/OpenGL/GL_DialogWindow.h index 02504a0a7..5287d8764 100644 --- a/Demos/OpenGL/GL_DialogWindow.h +++ b/Demos/OpenGL/GL_DialogWindow.h @@ -32,11 +32,13 @@ class btCollisionObject; #endif #else -#include + #ifdef _WINDOWS #include #include #include +#else +#include #endif #endif diff --git a/Demos/OpenGL/GlutDemoApplication.cpp b/Demos/OpenGL/GlutDemoApplication.cpp index 5e77c7503..1f39aac5f 100644 --- a/Demos/OpenGL/GlutDemoApplication.cpp +++ b/Demos/OpenGL/GlutDemoApplication.cpp @@ -1,4 +1,5 @@ +#ifndef _WINDOWS #include "GlutDemoApplication.h" @@ -81,5 +82,6 @@ void GlutDemoApplication::swapBuffers() } +#endif //_WINDOWS diff --git a/Demos/OpenGL/GlutStuff.cpp b/Demos/OpenGL/GlutStuff.cpp index cc2d95f43..867e1e150 100644 --- a/Demos/OpenGL/GlutStuff.cpp +++ b/Demos/OpenGL/GlutStuff.cpp @@ -13,6 +13,7 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +#ifndef _WINDOWS #include "DemoApplication.h" @@ -106,3 +107,4 @@ int glutmain(int argc, char **argv,int width,int height,const char* title,DemoAp } +#endif //_WINDOWS diff --git a/Demos/OpenGL/GlutStuff.h b/Demos/OpenGL/GlutStuff.h index 01ff53394..176d6ae7a 100644 --- a/Demos/OpenGL/GlutStuff.h +++ b/Demos/OpenGL/GlutStuff.h @@ -26,13 +26,15 @@ subject to the following restrictions: #include #else -#include + #ifdef _WINDOWS #include #include #include -#endif -#endif +#define BT_ACTIVE_ALT VK_LMENU +#else +#include + #define BT_KEY_K 'k' @@ -53,7 +55,8 @@ subject to the following restrictions: #define BT_ACTIVE_CTRL GLUT_ACTIVE_ALT #define BT_ACTIVE_SHIFT GLUT_ACTIVE_SHIFT - +#endif +#endif #if BT_USE_FREEGLUT #include "GL/freeglut_ext.h" //to be able to return from glutMainLoop() diff --git a/Demos/OpenGL/Win32AppMain.cpp b/Demos/OpenGL/Win32AppMain.cpp index 5cacc5d5f..647931506 100644 --- a/Demos/OpenGL/Win32AppMain.cpp +++ b/Demos/OpenGL/Win32AppMain.cpp @@ -37,8 +37,10 @@ DemoApplication* createDemo(); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC); void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC); - - +static bool sOpenGLInitialized = false; +static int sWidth = 0; +static int sHeight =0; +static int quitRequest = 0; // WinMain @@ -181,11 +183,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return 0; // Return case SIZE_MAXIMIZED: // Was Window Maximized? - gDemoApplication->reshape(LOWORD (lParam), HIWORD (lParam)); + sWidth = LOWORD (lParam); + sHeight = HIWORD (lParam); + if (sOpenGLInitialized) + { + gDemoApplication->reshape(sWidth,sHeight); + } return 0; // Return case SIZE_RESTORED: // Was Window Restored? - gDemoApplication->reshape(LOWORD (lParam), HIWORD (lParam)); + sWidth = LOWORD (lParam); + sHeight = HIWORD (lParam); + if (sOpenGLInitialized) + { + gDemoApplication->reshape(sWidth,sHeight); + } return 0; // Return } break; @@ -297,8 +309,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case WM_KEYDOWN: + printf("bla\n"); switch ( wParam ) { + case VK_CONTROL: case VK_PRIOR: case VK_NEXT: case VK_END: @@ -321,14 +335,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } case 'Q': case VK_ESCAPE: - PostQuitMessage(0); + { + quitRequest = 1; + PostQuitMessage(0); + } return 0; } return 0; case WM_CHAR: - gDemoApplication->keyboardCallback(wParam,0,0); + if (!quitRequest) + gDemoApplication->keyboardCallback(wParam,0,0); break; default: @@ -364,6 +382,8 @@ void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) // create and enable the render context (RC) *hRC = wglCreateContext( *hDC ); wglMakeCurrent( *hDC, *hRC ); + sOpenGLInitialized = true; + gDemoApplication->reshape(sWidth,sHeight); } @@ -371,6 +391,8 @@ void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC) void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) { + sOpenGLInitialized = false; + wglMakeCurrent( NULL, NULL ); wglDeleteContext( hRC ); ReleaseDC( hWnd, hDC );