From 60593f41ed7c33b5f4c64cdbc50d344de1a58b7d Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Thu, 16 Apr 2015 23:46:01 -0700 Subject: [PATCH] make OpenGL2 version work (still very rudimentary, no filled rendering, only debug wireframe) --- .../CommonInterfaces/CommonRenderInterface.h | 2 + .../ExampleBrowser/OpenGLExampleBrowser.cpp | 30 +++++++----- .../Importers/ImportBsp/ImportBspExample.cpp | 4 +- examples/OpenGLWindow/SimpleOpenGL2App.cpp | 48 +++++++++++++++++++ examples/OpenGLWindow/SimpleOpenGL2Renderer.h | 6 +++ 5 files changed, 76 insertions(+), 14 deletions(-) diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index db4d3fef6..cc4862905 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -32,6 +32,8 @@ struct CommonRenderInterface virtual int getScreenWidth() = 0; virtual int getScreenHeight() = 0; + virtual void resize(int width, int height) = 0; + virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)=0; virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)=0; virtual void drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)=0; diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index f5056ffb2..34b3830c9 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -51,7 +51,7 @@ static ExampleInterface* sCurrentDemo = 0; static b3AlignedObjectArray allNames; static class ExampleEntries* gAllExamples=0; - +static bool sUseOpenGL2 = false; bool drawGUI=true; extern bool useShadowMap; static bool visualWireframe=false; @@ -525,9 +525,11 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) int height=768; SimpleOpenGL3App* simpleApp=0; - bool useOpenGL2=false; - if (useOpenGL2) + sUseOpenGL2 =args.CheckCmdLineFlag("opengl2"); + + if (sUseOpenGL2 ) { + s_app = new SimpleOpenGL2App("AllBullet2Demos",width,height); s_app->m_renderer = new SimpleOpenGL2Renderer(width,height); } else @@ -567,7 +569,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) GL3TexLoader* myTexLoader = new GL3TexLoader; Gwen::Renderer::Base* gwenRenderer = 0; - if (useOpenGL2) + if (sUseOpenGL2 ) { gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); } else @@ -709,7 +711,10 @@ void OpenGLExampleBrowser::update(float deltaTime) if (renderGrid) { BT_PROFILE("Draw Grid"); + glPolygonOffset(3.0, 3); + glEnable(GL_POLYGON_OFFSET_FILL); s_app->drawGrid(dg); + } static int frameCount = 0; frameCount++; @@ -754,16 +759,17 @@ void OpenGLExampleBrowser::update(float deltaTime) // processProfileData(profWindow,false); { - // if (useOpenGL2) - //{ - // saveOpenGLState(width,height); - //} + if (sUseOpenGL2) + { + + saveOpenGLState(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight()); + } BT_PROFILE("Draw Gwen GUI"); gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight()); - //if (useOpenGL2) - //{ - // restoreOpenGLState(); - //} + if (sUseOpenGL2) + { + restoreOpenGLState(); + } } } toggle=1-toggle; diff --git a/examples/Importers/ImportBsp/ImportBspExample.cpp b/examples/Importers/ImportBsp/ImportBspExample.cpp index a3e80552e..5b3c39aaa 100644 --- a/examples/Importers/ImportBsp/ImportBspExample.cpp +++ b/examples/Importers/ImportBsp/ImportBspExample.cpp @@ -18,7 +18,7 @@ subject to the following restrictions: #include "btBulletDynamicsCommon.h" #include "LinearMath/btQuickprof.h" -#include "LinearMath/btIDebugDraw.h" + @@ -161,7 +161,7 @@ void BspDemo::initPhysics(const char* bspfilename) m_solver = new btSequentialImpulseConstraintSolver(); //ConstraintSolver* solver = new OdeConstraintSolver; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); - + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); m_dynamicsWorld->setGravity(grav); diff --git a/examples/OpenGLWindow/SimpleOpenGL2App.cpp b/examples/OpenGLWindow/SimpleOpenGL2App.cpp index 672a150f5..78dfa4f4b 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL2App.cpp @@ -25,6 +25,46 @@ #include #include "../CommonInterfaces/CommonRenderInterface.h" +static SimpleOpenGL2App* gApp2=0; + +static void Simple2ResizeCallback( float widthf, float heightf) +{ + int width = (int)widthf; + int height = (int)heightf; + if (gApp2->m_renderer) + gApp2->m_renderer->resize(width,height); + //gApp2->m_renderer->setScreenSize(width,height); + +} + +static void Simple2KeyboardCallback(int key, int state) +{ + if (key==B3G_ESCAPE && gApp2 && gApp2->m_window) + { + gApp2->m_window->setRequestExit(); + } else + { + //gApp2->defaultKeyboardCallback(key,state); + } +} + +void Simple2MouseButtonCallback( int button, int state, float x, float y) +{ + gApp2->defaultMouseButtonCallback(button,state,x,y); +} +void Simple2MouseMoveCallback( float x, float y) +{ + gApp2->defaultMouseMoveCallback(x,y); +} + +void Simple2WheelCallback( float deltax, float deltay) +{ + gApp2->defaultWheelCallback(deltax,deltay); +} + + + + struct SimpleOpenGL2AppInternalData { @@ -32,6 +72,7 @@ struct SimpleOpenGL2AppInternalData SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height) { + gApp2 = this; m_data = new SimpleOpenGL2AppInternalData; m_window = new b3gDefaultOpenGLWindow(); @@ -81,10 +122,17 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height) //m_instancingRenderer->InitShaders(); + m_window->setMouseMoveCallback(Simple2MouseMoveCallback); + m_window->setMouseButtonCallback(Simple2MouseButtonCallback); + m_window->setKeyboardCallback(Simple2KeyboardCallback); + m_window->setWheelCallback(Simple2WheelCallback); + m_window->setResizeCallback(Simple2ResizeCallback); + } SimpleOpenGL2App::~SimpleOpenGL2App() { + gApp2 = 0; delete m_data; } diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h index 9e1127380..766d0a2e4 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h @@ -21,6 +21,12 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface virtual CommonCameraInterface* getActiveCamera(); virtual void setActiveCamera(CommonCameraInterface* cam); + virtual void resize(int width, int height) + { + m_width = width; + m_height = height; + } + virtual void removeAllInstances();