prepare for Bullet 2 demo collection

This commit is contained in:
erwin coumans
2013-12-19 22:14:37 -08:00
parent abeea0c8b0
commit 12dd0daebc
9 changed files with 214 additions and 29 deletions

View File

@@ -0,0 +1,110 @@
#include "../../btgui/OpenGLWindow/SimpleOpenGL3App.h"
#include "Bullet3Common/b3Vector3.h"
#include "assert.h"
#include <stdio.h>
#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;i<numDemos;i++)
{
if (!strcmp(demoNames[i],item))
{
if (selectedDemo != i)
{
gReset = true;
selectedDemo = i;
printf("selected demo %s!\n", item);
}
}
}
*/
}
int main(int argc, char* argv[])
{
float dt = 1./120.f;
int width = 1024;
int height=768;
SimpleOpenGL3App* app = new SimpleOpenGL3App("AllBullet2Demos",width,height);
app->m_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;
}

View File

@@ -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

View File

@@ -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;i<numItems;i++)
combobox->AddItem(Gwen::Utility::StringToUnicode(items[i]));
{
Gwen::Controls::MenuItem* item = combobox->AddItem(Gwen::Utility::StringToUnicode(items[i]));
if (i==startItem)
combobox->OnItemSelected(item);
}
}

View File

@@ -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);
};

View File

@@ -101,7 +101,7 @@ enum
};
b3AlignedObjectArray<const char*> 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);
}

View File

@@ -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();