mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 21:30:09 +00:00
add preliminary glut replacement test for Bullet 2.x demos
This commit is contained in:
parent
87d44cbb74
commit
bae303c5da
@ -14,6 +14,7 @@ subject to the following restrictions:
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "DemoApplication.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
|
||||
@ -112,6 +113,8 @@ DemoApplication::~DemoApplication()
|
||||
|
||||
if (m_shapeDrawer)
|
||||
delete m_shapeDrawer;
|
||||
|
||||
//GLDebugResetFont(0,0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,6 +112,12 @@ public:
|
||||
|
||||
virtual ~DemoApplication();
|
||||
|
||||
void setDynamicsWorld(btDynamicsWorld* world)
|
||||
{
|
||||
m_dynamicsWorld=world;
|
||||
}
|
||||
|
||||
|
||||
btDynamicsWorld* getDynamicsWorld()
|
||||
{
|
||||
return m_dynamicsWorld;
|
||||
|
@ -41,7 +41,7 @@ subject to the following restrictions:
|
||||
#include <GL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <GL/glu.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -59,6 +59,19 @@ static int sScreenHeight = -1;
|
||||
void GLDebugResetFont(int screenWidth,int screenHeight)
|
||||
{
|
||||
|
||||
if (screenWidth==0 && screenHeight==0)
|
||||
{
|
||||
sScreenWidth = screenWidth;
|
||||
sScreenHeight = screenHeight;
|
||||
|
||||
if (sTexturesInitialized)
|
||||
{
|
||||
glDeleteTextures(1, &sTexture);
|
||||
glBindTexture(GL_TEXTURE_2D,0);
|
||||
sTexturesInitialized = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ((sScreenWidth == screenWidth) && (sScreenHeight == screenHeight))
|
||||
return;
|
||||
|
||||
|
@ -13,7 +13,7 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef _WINDOWS
|
||||
#ifndef DONT_USE_GLUT
|
||||
|
||||
#include "DemoApplication.h"
|
||||
|
||||
@ -71,6 +71,7 @@ static void glutDisplayCallback(void)
|
||||
gDemoApplication->displayCallback();
|
||||
}
|
||||
|
||||
#include <GL/glut.h>
|
||||
|
||||
int glutmain(int argc, char **argv,int width,int height,const char* title,DemoApplication* demoApp) {
|
||||
|
||||
@ -117,4 +118,4 @@ CGLSetParameter(cgl_context, kCGLCPSwapInterval, &swap_interval);
|
||||
}
|
||||
|
||||
|
||||
#endif //_WINDOWS
|
||||
#endif //DONT_USE_GLUT
|
||||
|
@ -15,51 +15,68 @@ subject to the following restrictions:
|
||||
#ifndef GLUT_STUFF_H
|
||||
#define GLUT_STUFF_H
|
||||
|
||||
#ifdef DONT_USE_GLUT
|
||||
#ifdef _WIN32//for glut.h
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#endif //DONT_USE_GLUT
|
||||
|
||||
//think different
|
||||
#if defined(__APPLE__) && !defined (VMDMESA)
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#ifndef DONT_USE_GLUT
|
||||
#include <GLUT/glut.h>
|
||||
#endif//DONT_USE_GLUT
|
||||
|
||||
#else//(__APPLE__) && !defined (VMDMESA)
|
||||
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#endif //_WINDOWS
|
||||
#endif //APPLE
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#define BT_ACTIVE_ALT VK_LMENU
|
||||
#define BT_ACTIVE_SHIFT VK_LSHIFT
|
||||
#define BT_ACTIVE_CTRL VK_LCONTROL
|
||||
#else //_WINDOWS
|
||||
|
||||
#ifdef DONT_USE_GLUT
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#define BT_ACTIVE_ALT 8192
|
||||
#define BT_ACTIVE_SHIFT 8193
|
||||
#define BT_ACTIVE_CTRL 8194
|
||||
#else//DONT_USE_GLUT
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif//_WIN32
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#define BT_KEY_K 'k'
|
||||
#define BT_KEY_LEFT GLUT_KEY_LEFT
|
||||
#define BT_KEY_RIGHT GLUT_KEY_RIGHT
|
||||
#define BT_KEY_UP GLUT_KEY_UP
|
||||
#define BT_KEY_DOWN GLUT_KEY_DOWN
|
||||
#define BT_KEY_F1 GLUT_KEY_F1
|
||||
#define BT_KEY_F2 GLUT_KEY_F2
|
||||
#define BT_KEY_F3 GLUT_KEY_F3
|
||||
#define BT_KEY_F4 GLUT_KEY_F4
|
||||
#define BT_KEY_F5 GLUT_KEY_F5
|
||||
#define BT_KEY_PAGEUP GLUT_KEY_PAGE_UP
|
||||
#define BT_KEY_PAGEDOWN GLUT_KEY_PAGE_DOWN
|
||||
#define BT_KEY_END GLUT_KEY_END
|
||||
#define BT_KEY_HOME GLUT_KEY_HOME
|
||||
#define BT_ACTIVE_ALT GLUT_ACTIVE_ALT
|
||||
#define BT_ACTIVE_CTRL GLUT_ACTIVE_ALT
|
||||
#define BT_ACTIVE_SHIFT GLUT_ACTIVE_SHIFT
|
||||
|
||||
#endif//DONT_USE_GLUT
|
||||
#endif//_WINDOWS
|
||||
#endif //(__APPLE__) && !defined (VMDMESA)
|
||||
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#define BT_ACTIVE_ALT VK_LMENU
|
||||
#define BT_ACTIVE_SHIFT VK_LSHIFT
|
||||
#else
|
||||
#define BT_KEY_K 'k'
|
||||
#define BT_KEY_LEFT GLUT_KEY_LEFT
|
||||
#define BT_KEY_RIGHT GLUT_KEY_RIGHT
|
||||
#define BT_KEY_UP GLUT_KEY_UP
|
||||
#define BT_KEY_DOWN GLUT_KEY_DOWN
|
||||
#define BT_KEY_F1 GLUT_KEY_F1
|
||||
#define BT_KEY_F2 GLUT_KEY_F2
|
||||
#define BT_KEY_F3 GLUT_KEY_F3
|
||||
#define BT_KEY_F4 GLUT_KEY_F4
|
||||
#define BT_KEY_F5 GLUT_KEY_F5
|
||||
#define BT_KEY_PAGEUP GLUT_KEY_PAGE_UP
|
||||
#define BT_KEY_PAGEDOWN GLUT_KEY_PAGE_DOWN
|
||||
#define BT_KEY_END GLUT_KEY_END
|
||||
#define BT_KEY_HOME GLUT_KEY_HOME
|
||||
#define BT_ACTIVE_ALT GLUT_ACTIVE_ALT
|
||||
#define BT_ACTIVE_CTRL GLUT_ACTIVE_ALT
|
||||
#define BT_ACTIVE_SHIFT GLUT_ACTIVE_SHIFT
|
||||
#endif
|
||||
|
||||
#if BT_USE_FREEGLUT
|
||||
#include "GL/freeglut_ext.h" //to be able to return from glutMainLoop()
|
||||
|
@ -36,6 +36,11 @@ public:
|
||||
///rgba input is in range [0..1] for each component
|
||||
inline void setPixel(int x,int y,const btVector4& rgba)
|
||||
{
|
||||
btAssert(x>=0);
|
||||
btAssert(y>=0);
|
||||
btAssert(x<m_width);
|
||||
btAssert(x<m_height);
|
||||
|
||||
unsigned char* pixel = &m_buffer[ (x+y*m_width) * 4];
|
||||
|
||||
pixel[0] = (unsigned char)(255.*rgba.getX());
|
||||
|
14
Demos3/BasicDemoConsole/main.cpp
Normal file
14
Demos3/BasicDemoConsole/main.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../../Demos/BasicDemo/BasicDemoPhysicsSetup.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
BasicDemoPhysicsSetup physicsSetup;
|
||||
GraphicsPhysicsBridge br;
|
||||
physicsSetup.initPhysics(br);
|
||||
physicsSetup.stepSimulation(1./60.);
|
||||
physicsSetup.exitPhysics();
|
||||
|
||||
printf("hello\n");
|
||||
}
|
26
Demos3/BasicDemoConsole/premake4.lua
Normal file
26
Demos3/BasicDemoConsole/premake4.lua
Normal file
@ -0,0 +1,26 @@
|
||||
project "App_BasicDemoConsole"
|
||||
|
||||
kind "ConsoleApp"
|
||||
targetdir "../../bin"
|
||||
|
||||
includedirs {"../../src"}
|
||||
configuration { "Windows" }
|
||||
-- links { "opengl32","glu32","gdi32","winmm", "user32" }
|
||||
files { "../../build3/bullet.rc" }
|
||||
-- configuration {"MacOSX"}
|
||||
--print "hello"
|
||||
-- linkoptions { "-framework Carbon -framework OpenGL -framework AGL -framework Glut" }
|
||||
-- configuration {"not Windows", "not MacOSX"}
|
||||
-- links {"GL","GLU","glut"}
|
||||
configuration{}
|
||||
|
||||
links {
|
||||
"BulletDynamics", "BulletCollision", "LinearMath"
|
||||
}
|
||||
|
||||
files {
|
||||
"*.cpp" ,
|
||||
"*.h",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.cpp",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.h"
|
||||
}
|
255
Demos3/BasicDemoCustomOpenGL2/main.cpp
Normal file
255
Demos3/BasicDemoCustomOpenGL2/main.cpp
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2014 Erwin Coumans http://bulletphysics.org
|
||||
|
||||
//This file is Copyright (c) 2014 Google Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
///This main.cpp replaces glut by Bullet 3 own platform management for OpenGL and input devices
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../../Demos/BasicDemo/BasicDemoPhysicsSetup.h"
|
||||
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "OpenGLWindow/MacOpenGLWindow.h"
|
||||
#else
|
||||
|
||||
#include "GL/glew.h"
|
||||
#ifdef _WIN32
|
||||
#include "OpenGLWindow/Win32OpenGLWindow.h"
|
||||
#else
|
||||
//let's cross the fingers it is Linux/X11
|
||||
#include "OpenGLWindow/X11OpenGLWindow.h"
|
||||
#endif //_WIN32
|
||||
#endif//__APPLE__
|
||||
|
||||
#include "../../Demos/OpenGL/DemoApplication.h"
|
||||
#include "../../Demos/OpenGL/GLDebugDrawer.h"
|
||||
|
||||
int sWidth = 800;
|
||||
int sHeight = 600;
|
||||
DemoApplication* gApp = 0;
|
||||
bool isShiftPressed = false;
|
||||
bool isCtrlPressed = false;
|
||||
bool isAltPressed = false;
|
||||
|
||||
/*
|
||||
todo: add wheel callback
|
||||
typedef void (*b3WheelCallback)(float deltax, float deltay);
|
||||
*/
|
||||
|
||||
void MyKeyboardCallback(int orgKeycode, int state)
|
||||
{
|
||||
int keycode = orgKeycode;
|
||||
|
||||
if (gApp)
|
||||
{
|
||||
|
||||
switch (orgKeycode)
|
||||
{
|
||||
case B3G_SHIFT:
|
||||
{
|
||||
isShiftPressed = (state==1);
|
||||
break;
|
||||
}
|
||||
case B3G_ALT:
|
||||
{
|
||||
isAltPressed = (state==1);
|
||||
break;
|
||||
}
|
||||
case B3G_CONTROL:
|
||||
{
|
||||
isCtrlPressed = (state==1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
if (state)
|
||||
{
|
||||
gApp->keyboardCallback(keycode,0,0);
|
||||
} else
|
||||
{
|
||||
gApp->keyboardUpCallback(keycode,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
void MyMouseMoveCallback( float x, float y)
|
||||
{
|
||||
if (gApp)
|
||||
{
|
||||
//printf("mouseMotionFunc %f,%f\n",x,y);
|
||||
gApp->mouseMotionFunc(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
if (gApp)
|
||||
{
|
||||
//printf("mouseFunc %d,%d, %f,%f\n",button,state,x,y);
|
||||
gApp->mouseFunc(button,1-state,x,y);
|
||||
}
|
||||
}
|
||||
|
||||
void MyResizeCallback(float width, float height)
|
||||
{
|
||||
sWidth = width;
|
||||
sHeight = height;
|
||||
if (gApp)
|
||||
{
|
||||
gApp->reshape(width,height);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||
//window->setKeyboardCallback(keyCallback);
|
||||
b3gWindowConstructionInfo wci;
|
||||
wci.m_openglVersion = 2;
|
||||
wci.m_width = sWidth;
|
||||
wci.m_height = sHeight;
|
||||
// wci.m_resizeCallback = MyResizeCallback;
|
||||
|
||||
window->createWindow(wci);
|
||||
window->setResizeCallback(MyResizeCallback);
|
||||
window->setMouseButtonCallback(MyMouseButtonCallback);
|
||||
|
||||
window->setMouseMoveCallback(MyMouseMoveCallback);
|
||||
window->setKeyboardCallback(MyKeyboardCallback);
|
||||
|
||||
//window->setWindowTitle("render test");
|
||||
|
||||
int majorGlVersion, minorGlVersion;
|
||||
|
||||
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
|
||||
{
|
||||
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
|
||||
exit(0);
|
||||
}
|
||||
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
||||
{
|
||||
float retinaScale = 1.f;
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifndef _WIN32
|
||||
//we need glewExperimental on Linux
|
||||
glewExperimental = GL_TRUE;
|
||||
#endif // _WIN32
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
|
||||
|
||||
GLuint err = glGetError();
|
||||
err = glGetError();
|
||||
btAssert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
retinaScale = window->getRetinaScale();
|
||||
|
||||
//primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
//sth_stash* font = initFont(primRenderer );
|
||||
//gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
|
||||
} else
|
||||
{
|
||||
//OpenGL 2.x
|
||||
/*gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
skin.SetRender( gwenRenderer );
|
||||
|
||||
pCanvas = new Gwen::Controls::Canvas( &skin );
|
||||
pCanvas->SetSize( sWidth, sHeight);
|
||||
pCanvas->SetDrawBackground( true );
|
||||
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
// glClearColor(0.2,0.2,0.2,1);
|
||||
|
||||
|
||||
|
||||
BasicDemoPhysicsSetup physicsSetup;
|
||||
GraphicsPhysicsBridge br;
|
||||
physicsSetup.initPhysics(br);
|
||||
|
||||
|
||||
struct MyAppie : public DemoApplication
|
||||
{
|
||||
virtual void initPhysics()
|
||||
{
|
||||
}
|
||||
virtual void clientMoveAndDisplay()
|
||||
{
|
||||
}
|
||||
virtual void swapBuffers()
|
||||
{
|
||||
}
|
||||
virtual void updateModifierKeys()
|
||||
{
|
||||
m_modifierKeys = 0;
|
||||
if (isAltPressed)
|
||||
m_modifierKeys |= BT_ACTIVE_ALT;
|
||||
|
||||
if (isCtrlPressed)
|
||||
m_modifierKeys |= BT_ACTIVE_CTRL;
|
||||
|
||||
if (isShiftPressed)
|
||||
m_modifierKeys |= BT_ACTIVE_SHIFT;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
{
|
||||
MyAppie appie;
|
||||
appie.setDynamicsWorld(physicsSetup.m_dynamicsWorld);
|
||||
appie.reshape(sWidth,sHeight);
|
||||
appie.setShadows(true);
|
||||
gApp = &appie;
|
||||
GLDebugDrawer draw;
|
||||
physicsSetup.m_dynamicsWorld->setDebugDrawer(&draw);
|
||||
btClock timer;
|
||||
unsigned long prevTime = timer.getTimeMicroseconds();
|
||||
|
||||
do
|
||||
{
|
||||
unsigned long curTime = timer.getTimeMicroseconds();
|
||||
if (!appie.isIdle())
|
||||
{
|
||||
physicsSetup.stepSimulation((curTime-prevTime)*(1./1000000.));
|
||||
}
|
||||
prevTime = curTime;
|
||||
window->startRendering();
|
||||
br.syncPhysicsToGraphics(physicsSetup.m_dynamicsWorld);
|
||||
appie.renderme();
|
||||
physicsSetup.m_dynamicsWorld->debugDrawWorld();
|
||||
window->endRendering();
|
||||
|
||||
} while (!window->requestedExit());
|
||||
}
|
||||
window->closeWindow();
|
||||
delete window;
|
||||
|
||||
physicsSetup.exitPhysics();
|
||||
|
||||
|
||||
printf("hello\n");
|
||||
}
|
34
Demos3/BasicDemoCustomOpenGL2/premake4.lua
Normal file
34
Demos3/BasicDemoCustomOpenGL2/premake4.lua
Normal file
@ -0,0 +1,34 @@
|
||||
project "App_BasicDemoCustomOpenGL2"
|
||||
|
||||
kind "ConsoleApp"
|
||||
targetdir "../../bin"
|
||||
|
||||
includedirs {
|
||||
"../../src",
|
||||
"../../btgui"
|
||||
}
|
||||
|
||||
defines { "DONT_USE_GLUT"}
|
||||
|
||||
initOpenGL()
|
||||
initGlew()
|
||||
|
||||
links {
|
||||
"OpenGL_Window","BulletDynamics", "BulletCollision", "LinearMath"
|
||||
}
|
||||
|
||||
files {
|
||||
"*.cpp" ,
|
||||
"*.h",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.cpp",
|
||||
"../../Demos/BasicDemo/BasicDemoPhysicsSetup.h",
|
||||
"../../Demos/OpenGL/DemoApplication.cpp",
|
||||
"../../Demos/OpenGL/DemoApplication.h",
|
||||
"../../Demos/OpenGL/GL_ShapeDrawer.cpp",
|
||||
"../../Demos/OpenGL/GL_ShapeDrawer.h",
|
||||
"../../Demos/OpenGL/GL_ShapeDrawer.cpp",
|
||||
"../../Demos/OpenGL/GLDebugDrawer.cpp",
|
||||
"../../Demos/OpenGL/GLDebugDrawer.h",
|
||||
"../../Demos/OpenGL/GLDebugFont.cpp",
|
||||
"../../Demos/OpenGL/GLDebugFont.h"
|
||||
}
|
@ -65,7 +65,7 @@ int getAsciiCodeFromVirtualKeycode(int virtualKeyCode)
|
||||
}
|
||||
if (virtualKeyCode >= 'A' && virtualKeyCode <= 'Z')
|
||||
{
|
||||
return virtualKeyCode;
|
||||
return virtualKeyCode+32;//todo: fix the ascii A vs a input
|
||||
}
|
||||
switch (virtualKeyCode)
|
||||
{
|
||||
@ -170,7 +170,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int keycode = getAsciiCodeFromVirtualKeycode(wParam);
|
||||
|
||||
if (keycode>=0 && sData && sData->m_keyboardCallback && ((HIWORD(lParam) & KF_REPEAT) == 0))
|
||||
if (keycode>=0 && sData && sData->m_keyboardCallback)// && ((HIWORD(lParam) & KF_REPEAT) == 0))
|
||||
{
|
||||
int state = 1;
|
||||
(*sData->m_keyboardCallback)(keycode,state);
|
||||
|
@ -104,6 +104,11 @@
|
||||
if findOpenGL() then
|
||||
include "../Demos3/AllBullet2Demos"
|
||||
include "../Demos3/GpuDemos"
|
||||
--include"../Demos3/BasicDemoConsole"
|
||||
--include"../Demos3/BasicDemoCustomOpenGL2"
|
||||
|
||||
|
||||
|
||||
-- include "../Demos3/CpuDemos"
|
||||
-- include "../Demos3/Wavefront"
|
||||
-- include "../btgui/MultiThreading"
|
||||
|
Loading…
Reference in New Issue
Block a user