From 12dd0daebc15ded89876095d451199eea17392a9 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Thu, 19 Dec 2013 22:14:37 -0800 Subject: [PATCH] prepare for Bullet 2 demo collection --- Demos3/AllBullet2Demos/main.cpp | 110 +++++++++++++++++++ Demos3/AllBullet2Demos/premake4.lua | 33 ++++++ Demos3/GpuDemos/gwenUserInterface.cpp | 14 ++- Demos3/GpuDemos/gwenUserInterface.h | 2 +- Demos3/GpuDemos/main_opengl3core.cpp | 4 +- Demos3/SimpleOpenGL3/main.cpp | 2 +- btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h | 2 + btgui/OpenGLWindow/SimpleOpenGL3App.cpp | 72 +++++++++--- build3/premake4.lua | 4 +- 9 files changed, 214 insertions(+), 29 deletions(-) create mode 100644 Demos3/AllBullet2Demos/main.cpp create mode 100644 Demos3/AllBullet2Demos/premake4.lua diff --git a/Demos3/AllBullet2Demos/main.cpp b/Demos3/AllBullet2Demos/main.cpp new file mode 100644 index 000000000..aef69b9e0 --- /dev/null +++ b/Demos3/AllBullet2Demos/main.cpp @@ -0,0 +1,110 @@ +#include "../../btgui/OpenGLWindow/SimpleOpenGL3App.h" +#include "Bullet3Common/b3Vector3.h" +#include "assert.h" +#include + +#include "../GpuDemos/gwenUserInterface.h" + +GwenUserInterface* gui = 0; + +static void MyMouseMoveCallback( float x, float y) +{ + bool handled = false; + if (gui) + handled = gui->mouseMoveCallback(x,y); + if (!handled) + b3DefaultMouseMoveCallback(x,y); +} +static void MyMouseButtonCallback(int button, int state, float x, float y) +{ + bool handled = false; + //try picking first + if (gui) + handled = gui->mouseButtonCallback(button,state,x,y); + + if (!handled) + b3DefaultMouseButtonCallback(button,state,x,y); +} + + + +void MyComboBoxCallback(int comboId, const char* item) +{ + printf("comboId = %d, item = %s\n",comboId, item); + /*int numDemos = demoNames.size(); + for (int i=0;im_instancingRenderer->setCameraDistance(13); + app->m_instancingRenderer->setCameraPitch(0); + app->m_instancingRenderer->setCameraTargetPosition(b3MakeVector3(0,0,0)); + app->m_window->setMouseMoveCallback(MyMouseMoveCallback); + app->m_window->setMouseButtonCallback(MyMouseButtonCallback); + + + GLint err = glGetError(); + assert(err==GL_NO_ERROR); + + sth_stash* fontstash=0; + gui = new GwenUserInterface; + gui->init(width,height,fontstash,app->m_window->getRetinaScale()); + + const char* names[] = {"test1", "test2","test3"}; + gui->registerComboBox(13,3,&names[0],1); + const char* names2[] = {"comboF", "comboG","comboH"}; + gui->registerComboBox(2,3,&names2[0],1); + + gui->setComboBoxCallback(MyComboBoxCallback); + + + do + { + + GLint err = glGetError(); + assert(err==GL_NO_ERROR); + app->m_instancingRenderer->init(); + app->m_instancingRenderer->updateCamera(); + + app->drawGrid(); + char bla[1024]; + static int frameCount = 0; + frameCount++; + sprintf(bla,"Simple test frame %d", frameCount); + + app->drawText(bla,10,10); + + static int toggle = 1; + if (1) + { + gui->draw(app->m_instancingRenderer->getScreenWidth(),app->m_instancingRenderer->getScreenHeight()); + } + toggle=1-toggle; + app->swapBuffer(); + } while (!app->m_window->requestedExit()); + + delete gui; + + delete app; + return 0; +} diff --git a/Demos3/AllBullet2Demos/premake4.lua b/Demos3/AllBullet2Demos/premake4.lua new file mode 100644 index 000000000..da9429780 --- /dev/null +++ b/Demos3/AllBullet2Demos/premake4.lua @@ -0,0 +1,33 @@ + + project "App_AllBullet2Demos" + + language "C++" + + kind "ConsoleApp" + targetdir "../../bin" + + includedirs { + ".", + "../../src", + "../../btgui" + } + + initOpenGL() + initGlew() + + links{"gwen", "OpenGL_Window","OpenGL_TrueTypeFont","BulletSoftBody","BulletDynamics","BulletCollision","LinearMath"} + + files { + "**.cpp", + "**.h", + "../../src/Bullet3Common/**.cpp", + "../../src/Bullet3Common/**.h", + "../../btgui/Timing/b3Clock.cpp", + "../../btgui/Timing/b3Clock.h", + "../GpuDemos/gwenUserInterface.cpp", + "../GpuDemos/gwenUserInterface.h" + } + +if os.is("MacOSX") then + links{"Cocoa.framework"} +end diff --git a/Demos3/GpuDemos/gwenUserInterface.cpp b/Demos3/GpuDemos/gwenUserInterface.cpp index 9c98fdc60..e8c60c8a9 100644 --- a/Demos3/GpuDemos/gwenUserInterface.cpp +++ b/Demos3/GpuDemos/gwenUserInterface.cpp @@ -228,8 +228,8 @@ void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float - Gwen::UnicodeString str2(L"OpenCL"); - tab->AddPage(str2); +// Gwen::UnicodeString str2(L"OpenCL"); +// tab->AddPage(str2); //Gwen::UnicodeString str3(L"page3"); // tab->AddPage(str3); @@ -291,7 +291,7 @@ void GwenUserInterface::setComboBoxCallback(b3ComboBoxCallback callback) m_data->m_comboBoxCallback = callback; } -void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const char** items) +void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const char** items, int startItem) { Gwen::Controls::ComboBox* combobox = new Gwen::Controls::ComboBox(m_data->m_demoPage->GetPage()); MyComboBoxHander* handler = new MyComboBoxHander(m_data, comboboxId); @@ -303,8 +303,12 @@ void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const cha combobox->SetWidth( 100 ); //box->SetPos(120,130); for (int i=0;iAddItem(Gwen::Utility::StringToUnicode(items[i])); - + { + Gwen::Controls::MenuItem* item = combobox->AddItem(Gwen::Utility::StringToUnicode(items[i])); + if (i==startItem) + combobox->OnItemSelected(item); + } + } diff --git a/Demos3/GpuDemos/gwenUserInterface.h b/Demos3/GpuDemos/gwenUserInterface.h index 9a48ad5cf..443df3e66 100644 --- a/Demos3/GpuDemos/gwenUserInterface.h +++ b/Demos3/GpuDemos/gwenUserInterface.h @@ -29,7 +29,7 @@ class GwenUserInterface void registerToggleButton(int buttonId, const char* name); void setComboBoxCallback(b3ComboBoxCallback callback); - void registerComboBox(int buttonId, int numItems, const char** items); + void registerComboBox(int buttonId, int numItems, const char** items, int startItem = 0); void setStatusBarMessage(const char* message, bool isLeft=true); }; diff --git a/Demos3/GpuDemos/main_opengl3core.cpp b/Demos3/GpuDemos/main_opengl3core.cpp index 303a77c84..f0845ce8a 100644 --- a/Demos3/GpuDemos/main_opengl3core.cpp +++ b/Demos3/GpuDemos/main_opengl3core.cpp @@ -101,7 +101,7 @@ enum }; b3AlignedObjectArray demoNames; -int selectedDemo = 0; +int selectedDemo = 1; GpuDemo::CreateFunc* allDemos[]= { //ConcaveCompound2Scene::MyCreateFunc, @@ -730,7 +730,7 @@ int main(int argc, char* argv[]) delete demo; } - gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0]); + gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0],selectedDemo); gui->setComboBoxCallback(MyComboBoxCallback); } diff --git a/Demos3/SimpleOpenGL3/main.cpp b/Demos3/SimpleOpenGL3/main.cpp index 4e8d9d142..91faf454a 100644 --- a/Demos3/SimpleOpenGL3/main.cpp +++ b/Demos3/SimpleOpenGL3/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) char bla[1024]; static int frameCount = 0; frameCount++; - sprintf(bla,"Simple test frame %d\n", frameCount); + sprintf(bla,"Simple test frame %d", frameCount); app->drawText(bla,10,10); app->swapBuffer(); diff --git a/btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h b/btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h index 8179730bc..e938ad453 100644 --- a/btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h +++ b/btgui/OpenGLWindow/GwenOpenGL3CoreRenderer.h @@ -145,6 +145,8 @@ public: } virtual void End() { + glDisable(GL_BLEND); + } virtual void StartClip() diff --git a/btgui/OpenGLWindow/SimpleOpenGL3App.cpp b/btgui/OpenGLWindow/SimpleOpenGL3App.cpp index 469b6cad9..15982df15 100644 --- a/btgui/OpenGLWindow/SimpleOpenGL3App.cpp +++ b/btgui/OpenGLWindow/SimpleOpenGL3App.cpp @@ -18,13 +18,20 @@ #include "OpenGLWindow/GLInstancingRenderer.h" #include "Bullet3Common/b3Vector3.h" +#include "Bullet3Common/b3Logging.h" #include "../btgui/OpenGLTrueTypeFont/fontstash.h" #include "../btgui/OpenGLWindow/TwFonts.h" +#include "OpenGLTrueTypeFont/opengl_fontstashcallbacks.h" +#include struct SimpleInternalData { - GLuint m_fontTextureId; + GLuint m_fontTextureId; + struct sth_stash* m_fontStash; + OpenGL2RenderCallbacks* m_renderCallbacks; + int m_droidRegular; + }; static SimpleOpenGL3App* gApp=0; @@ -57,6 +64,7 @@ static GLuint BindFont(const CTexFont *_Font) return TexID; } +extern char OpenSansData[]; SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height) { @@ -91,9 +99,43 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height) TwGenerateDefaultFonts(); m_data->m_fontTextureId = BindFont(g_DefaultNormalFont); + + + { + GLint err; + + int datasize; + + float sx,sy,dx,dy,lh; + GLuint texture; + m_data->m_renderCallbacks = new OpenGL2RenderCallbacks(m_primRenderer); + m_data->m_fontStash = sth_create(512,512,m_data->m_renderCallbacks);//256,256);//,1024);//512,512); + err = glGetError(); + assert(err==GL_NO_ERROR); + + if (!m_data->m_fontStash) + { + b3Warning("Could not create stash"); + //fprintf(stderr, "Could not create stash.\n"); + } + int droidRegular=0; + + char* data2 = OpenSansData; + unsigned char* data = (unsigned char*) data2; + if (!(m_data->m_droidRegular = sth_add_font_from_memory(m_data->m_fontStash, data))) + { + b3Warning("error!\n"); + } + err = glGetError(); + assert(err==GL_NO_ERROR); + } } + + + + void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY) { @@ -102,32 +144,26 @@ void SimpleOpenGL3App::drawText( const char* txt, int posX, int posY) // //printf("str = %s\n",unicodeText); - int xpos=0; - int ypos=0; - float dx; + + float dx=0; int measureOnly=0; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* - if (m_useTrueTypeFont) + + if (1)//m_useTrueTypeFont) { + bool measureOnly = false; - float yoffset = 0.f; - if (m_retinaScale==2.0f) - { - yoffset = -12; - } - Translate(r); - sth_draw_text(m_font, - 1,m_fontScaling, - r.x,r.y+yoffset, - unicodeText,&dx, m_screenWidth,m_screenHeight,measureOnly,m_retinaScale); - + float fontSize= 64;//512;//128; + sth_draw_text(m_data->m_fontStash, + m_data->m_droidRegular,fontSize,posX,posY, + txt,&dx, this->m_instancingRenderer->getScreenWidth(),this->m_instancingRenderer->getScreenHeight(),measureOnly,m_window->getRetinaScale()); + sth_end_draw(m_data->m_fontStash); + sth_flush_draw(m_data->m_fontStash); } else - */ { //float width = 0.f; int pos=0; diff --git a/build3/premake4.lua b/build3/premake4.lua index c3b21c288..693b148f2 100644 --- a/build3/premake4.lua +++ b/build3/premake4.lua @@ -82,7 +82,7 @@ language "C++" - + include "../Demos3/AllBullet2Demos" include "../Demos3/GpuDemos" -- include "../Demos3/CpuDemos" @@ -110,7 +110,7 @@ include "../Demos3/SimpleOpenGL3" include "../test/OpenCL/ParallelPrimitives" include "../test/OpenCL/RadixSortBenchmark" - + include "../src/BulletSoftBody" include "../src/BulletDynamics" include "../src/BulletCollision" include "../src/LinearMath"