Removed many memoryleaks in Example Browser, reducing some technical debt.

When running the Example Browser with Basic Example, 'visual leak detector' show no leak.
Many other individual examples still leak, so it is work-in-progress.
Disabled the profiler window (too many leaks)
This commit is contained in:
erwin coumans
2016-07-16 00:55:56 -07:00
parent 797680a535
commit f9762d63ab
17 changed files with 521 additions and 316 deletions

View File

@@ -44,7 +44,7 @@ public:
CProfileIterator* profIter; CProfileIterator* profIter;
class MyMenuItems* m_menuItems;
MyProfileWindow ( Gwen::Controls::Base* pParent) MyProfileWindow ( Gwen::Controls::Base* pParent)
: Gwen::Controls::WindowControl( pParent ), : Gwen::Controls::WindowControl( pParent ),
profIter(0) profIter(0)
@@ -83,6 +83,12 @@ public:
} }
virtual ~MyProfileWindow()
{
delete m_node;
delete m_ctrl;
}
float dumpRecursive(CProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode) float dumpRecursive(CProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode)
{ {
@@ -266,11 +272,16 @@ public:
MyProfileWindow* setupProfileWindow(GwenInternalData* data) MyProfileWindow* setupProfileWindow(GwenInternalData* data)
{ {
MyMenuItems* menuItems = new MyMenuItems; MyMenuItems* menuItems = new MyMenuItems;
MyProfileWindow* profWindow = new MyProfileWindow(data->pCanvas); MyProfileWindow* profWindow = new MyProfileWindow(data->pCanvas);
//profWindow->SetHidden(true); //profWindow->SetHidden(true);
profWindow->profIter = CProfileManager::Get_Iterator();
profWindow->m_menuItems = menuItems;
//profWindow->profIter = CProfileManager::Get_Iterator();
data->m_viewMenu->GetMenu()->AddItem( L"Profiler", menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::MenuItemSelect); data->m_viewMenu->GetMenu()->AddItem( L"Profiler", menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::MenuItemSelect);
menuItems->m_profWindow = profWindow; menuItems->m_profWindow = profWindow;
return profWindow; return profWindow;
} }
@@ -290,5 +301,6 @@ void profileWindowSetVisible(MyProfileWindow* window, bool visible)
} }
void destroyProfileWindow(MyProfileWindow* window) void destroyProfileWindow(MyProfileWindow* window)
{ {
CProfileManager::Release_Iterator(window->profIter);
delete window; delete window;
} }

View File

@@ -45,7 +45,10 @@ struct GwenInternalData
Gwen::Controls::ListBox* m_TextOutput; Gwen::Controls::ListBox* m_TextOutput;
Gwen::Controls::Label* m_exampleInfoGroupBox; Gwen::Controls::Label* m_exampleInfoGroupBox;
Gwen::Controls::ListBox* m_exampleInfoTextOutput; Gwen::Controls::ListBox* m_exampleInfoTextOutput;
struct MyTestMenuBar* m_menubar;
Gwen::Controls::StatusBar* m_bar;
Gwen::Controls::ScrollControl* m_windowRight;
Gwen::Controls::TabControl* m_tab;
int m_curYposition; int m_curYposition;

View File

@@ -17,28 +17,6 @@ GwenUserInterface::GwenUserInterface()
} }
GwenUserInterface::~GwenUserInterface()
{
for (int i=0;i<m_data->m_handlers.size();i++)
{
delete m_data->m_handlers[i];
}
m_data->m_handlers.clear();
delete m_data->pCanvas;
delete m_data;
}
class MyMenuItems : public Gwen::Controls::Base class MyMenuItems : public Gwen::Controls::Base
{ {
public: public:
@@ -46,17 +24,17 @@ public:
b3FileOpenCallback m_fileOpenCallback; b3FileOpenCallback m_fileOpenCallback;
b3QuitCallback m_quitCallback; b3QuitCallback m_quitCallback;
MyMenuItems() :Gwen::Controls::Base(0),m_fileOpenCallback(0) MyMenuItems() :Gwen::Controls::Base(0), m_fileOpenCallback(0)
{ {
} }
void myQuitApp( Gwen::Controls::Base* pControl ) void myQuitApp(Gwen::Controls::Base* pControl)
{ {
if (m_quitCallback) if (m_quitCallback)
{ {
(*m_quitCallback)(); (*m_quitCallback)();
} }
} }
void fileOpen( Gwen::Controls::Base* pControl ) void fileOpen(Gwen::Controls::Base* pControl)
{ {
if (m_fileOpenCallback) if (m_fileOpenCallback)
{ {
@@ -66,6 +44,8 @@ public:
}; };
struct MyTestMenuBar : public Gwen::Controls::MenuStrip struct MyTestMenuBar : public Gwen::Controls::MenuStrip
{ {
@@ -76,23 +56,63 @@ struct MyTestMenuBar : public Gwen::Controls::MenuStrip
MyTestMenuBar(Gwen::Controls::Base* pParent) MyTestMenuBar(Gwen::Controls::Base* pParent)
:Gwen::Controls::MenuStrip(pParent) :Gwen::Controls::MenuStrip(pParent)
{ {
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent ); // Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
{ {
m_menuItems = new MyMenuItems(); m_menuItems = new MyMenuItems();
m_menuItems->m_fileOpenCallback = 0; m_menuItems->m_fileOpenCallback = 0;
m_menuItems->m_quitCallback = 0; m_menuItems->m_quitCallback = 0;
m_fileMenu = AddItem( L"File" ); m_fileMenu = AddItem(L"File");
m_fileMenu->GetMenu()->AddItem(L"Open",m_menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::fileOpen); m_fileMenu->GetMenu()->AddItem(L"Open", m_menuItems, (Gwen::Event::Handler::Function)&MyMenuItems::fileOpen);
m_fileMenu->GetMenu()->AddItem(L"Quit",m_menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp); m_fileMenu->GetMenu()->AddItem(L"Quit", m_menuItems, (Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
m_viewMenu = AddItem( L"View" ); m_viewMenu = AddItem(L"View");
} }
} }
virtual ~MyTestMenuBar()
{
delete m_menuItems;
}
}; };
void GwenUserInterface::exit()
{
//m_data->m_menubar->RemoveAllChildren();
delete m_data->m_tab;
delete m_data->m_windowRight;
delete m_data->m_leftStatusBar;
delete m_data->m_TextOutput;
delete m_data->m_rightStatusBar;
delete m_data->m_bar;
delete m_data->m_menubar;
m_data->m_menubar = 0;
delete m_data->pCanvas;
m_data->pCanvas = 0;
}
GwenUserInterface::~GwenUserInterface()
{
for (int i=0;i<m_data->m_handlers.size();i++)
{
delete m_data->m_handlers[i];
}
m_data->m_handlers.clear();
delete m_data;
}
void GwenUserInterface::resize(int width, int height) void GwenUserInterface::resize(int width, int height)
{ {
m_data->pCanvas->SetSize(width,height); m_data->pCanvas->SetSize(width,height);
@@ -232,6 +252,7 @@ void GwenUserInterface::setStatusBarMessage(const char* message, bool isLeft)
} }
} }
void GwenUserInterface::registerFileOpenCallback(b3FileOpenCallback callback) void GwenUserInterface::registerFileOpenCallback(b3FileOpenCallback callback)
{ {
m_data->m_menuItems->m_fileOpenCallback = callback; m_data->m_menuItems->m_fileOpenCallback = callback;
@@ -250,6 +271,7 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
m_data->skin.SetRender( m_data->pRenderer ); m_data->skin.SetRender( m_data->pRenderer );
m_data->pCanvas= new Gwen::Controls::Canvas( &m_data->skin ); m_data->pCanvas= new Gwen::Controls::Canvas( &m_data->skin );
m_data->pCanvas->SetSize( width,height); m_data->pCanvas->SetSize( width,height);
m_data->pCanvas->SetDrawBackground( false); m_data->pCanvas->SetDrawBackground( false);
@@ -260,24 +282,31 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
MyTestMenuBar* menubar = new MyTestMenuBar(m_data->pCanvas); MyTestMenuBar* menubar = new MyTestMenuBar(m_data->pCanvas);
m_data->m_viewMenu = menubar->m_viewMenu; m_data->m_viewMenu = menubar->m_viewMenu;
m_data->m_menuItems = menubar->m_menuItems; m_data->m_menuItems = menubar->m_menuItems;
m_data->m_menubar = menubar;
Gwen::Controls::StatusBar* bar = new Gwen::Controls::StatusBar(m_data->pCanvas); Gwen::Controls::StatusBar* bar = new Gwen::Controls::StatusBar(m_data->pCanvas);
m_data->m_bar = bar;
m_data->m_rightStatusBar = new Gwen::Controls::Label( bar ); m_data->m_rightStatusBar = new Gwen::Controls::Label( bar );
m_data->m_rightStatusBar->SetWidth(width/2); m_data->m_rightStatusBar->SetWidth(width/2);
//m_data->m_rightStatusBar->SetText( L"Label Added to Right" ); //m_data->m_rightStatusBar->SetText( L"Label Added to Right" );
bar->AddControl( m_data->m_rightStatusBar, true ); bar->AddControl( m_data->m_rightStatusBar, true );
m_data->m_TextOutput = new Gwen::Controls::ListBox( m_data->pCanvas ); m_data->m_TextOutput = new Gwen::Controls::ListBox( m_data->pCanvas );
m_data->m_TextOutput->Dock( Gwen::Pos::Bottom ); m_data->m_TextOutput->Dock( Gwen::Pos::Bottom );
m_data->m_TextOutput->SetHeight( 100 ); m_data->m_TextOutput->SetHeight( 100 );
m_data->m_leftStatusBar = new Gwen::Controls::Label( bar ); m_data->m_leftStatusBar = new Gwen::Controls::Label( bar );
//m_data->m_leftStatusBar->SetText( L"Label Added to Left" ); //m_data->m_leftStatusBar->SetText( L"Label Added to Left" );
m_data->m_leftStatusBar->SetWidth(width/2); m_data->m_leftStatusBar->SetWidth(width/2);
bar->AddControl( m_data->m_leftStatusBar,false); bar->AddControl( m_data->m_leftStatusBar,false);
//Gwen::KeyboardFocus //Gwen::KeyboardFocus
/*Gwen::Controls::GroupBox* box = new Gwen::Controls::GroupBox(m_data->pCanvas); /*Gwen::Controls::GroupBox* box = new Gwen::Controls::GroupBox(m_data->pCanvas);
box->SetText("text"); box->SetText("text");
@@ -289,11 +318,14 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
windowRight->SetWidth(250); windowRight->SetWidth(250);
windowRight->SetHeight(250); windowRight->SetHeight(250);
windowRight->SetScroll(false,true); windowRight->SetScroll(false,true);
m_data->m_windowRight = windowRight;
//windowLeft->SetSkin( //windowLeft->SetSkin(
Gwen::Controls::TabControl* tab = new Gwen::Controls::TabControl(windowRight); Gwen::Controls::TabControl* tab = new Gwen::Controls::TabControl(windowRight);
m_data->m_tab = tab;
//tab->SetHeight(300); //tab->SetHeight(300);
tab->SetWidth(240); tab->SetWidth(240);
@@ -308,6 +340,7 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
// Gwen::UnicodeString str2(L"OpenCL"); // Gwen::UnicodeString str2(L"OpenCL");
// tab->AddPage(str2); // tab->AddPage(str2);
//Gwen::UnicodeString str3(L"page3"); //Gwen::UnicodeString str3(L"page3");
@@ -389,7 +422,6 @@ void GwenUserInterface::init(int width, int height,Gwen::Renderer::Base* rendere
m_data->m_exampleInfoTextOutput = new Gwen::Controls::ListBox(m_data->m_explorerPage->GetPage()); m_data->m_exampleInfoTextOutput = new Gwen::Controls::ListBox(m_data->m_explorerPage->GetPage());
//m_data->m_exampleInfoTextOutput->Dock( Gwen::Pos::Bottom ); //m_data->m_exampleInfoTextOutput->Dock( Gwen::Pos::Bottom );
m_data->m_exampleInfoTextOutput->SetPos(2, 332); m_data->m_exampleInfoTextOutput->SetPos(2, 332);
m_data->m_exampleInfoTextOutput->SetHeight( 150 ); m_data->m_exampleInfoTextOutput->SetHeight( 150 );

View File

@@ -26,6 +26,7 @@ class GwenUserInterface
virtual ~GwenUserInterface(); virtual ~GwenUserInterface();
void init(int width, int height,Gwen::Renderer::Base* gwenRenderer,float retinaScale); void init(int width, int height,Gwen::Renderer::Base* gwenRenderer,float retinaScale);
void exit();
void setFocus(); void setFocus();
void forceUpdateScrollBars(); void forceUpdateScrollBars();

View File

@@ -42,19 +42,65 @@
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h" #include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
#include "../Importers/ImportBullet/SerializeSetup.h" #include "../Importers/ImportBullet/SerializeSetup.h"
#include "Bullet3Common/b3HashMap.h"
struct GL3TexLoader : public MyTextureLoader
{
b3HashMap<b3HashString, GLint> m_hashMap;
virtual void LoadTexture(Gwen::Texture* pTexture)
{
Gwen::String namestr = pTexture->name.Get();
const char* n = namestr.c_str();
GLint* texIdPtr = m_hashMap[n];
if (texIdPtr)
{
pTexture->m_intData = *texIdPtr;
}
}
virtual void FreeTexture(Gwen::Texture* pTexture)
{
}
};
struct OpenGLExampleBrowserInternalData
{
Gwen::Renderer::Base* m_gwenRenderer;
CommonGraphicsApp* m_app;
// MyProfileWindow* m_profWindow;
btAlignedObjectArray<Gwen::Controls::TreeNode*> m_nodes;
GwenUserInterface* m_gui;
GL3TexLoader* m_myTexLoader;
struct MyMenuItemHander* m_handler2;
btAlignedObjectArray<MyMenuItemHander*> m_handlers;
OpenGLExampleBrowserInternalData()
: m_gwenRenderer(0),
m_app(0),
// m_profWindow(0),
m_gui(0),
m_myTexLoader(0),
m_handler2(0)
{
}
};
static CommonGraphicsApp* s_app=0; static CommonGraphicsApp* s_app=0;
static CommonWindowInterface* s_window = 0; static CommonWindowInterface* s_window = 0;
static CommonParameterInterface* s_parameterInterface=0; static CommonParameterInterface* s_parameterInterface=0;
static CommonRenderInterface* s_instancingRenderer=0; static CommonRenderInterface* s_instancingRenderer=0;
static OpenGLGuiHelper* s_guiHelper=0; static OpenGLGuiHelper* s_guiHelper=0;
static MyProfileWindow* s_profWindow =0; //static MyProfileWindow* s_profWindow =0;
static SharedMemoryInterface* sSharedMem = 0; static SharedMemoryInterface* sSharedMem = 0;
#define DEMO_SELECTION_COMBOBOX 13 #define DEMO_SELECTION_COMBOBOX 13
const char* startFileName = "0_Bullet3Demo.txt"; const char* startFileName = "0_Bullet3Demo.txt";
char staticPngFileName[1024]; char staticPngFileName[1024];
static GwenUserInterface* gui = 0; //static GwenUserInterface* gui = 0;
static GwenUserInterface* gui2 = 0;
static int sCurrentDemoIndex = -1; static int sCurrentDemoIndex = -1;
static int sCurrentHightlighted = 0; static int sCurrentHightlighted = 0;
static CommonExampleInterface* sCurrentDemo = 0; static CommonExampleInterface* sCurrentDemo = 0;
@@ -123,9 +169,9 @@ void MyKeyboardCallback(int key, int state)
//b3Printf("key=%d, state=%d", key, state); //b3Printf("key=%d, state=%d", key, state);
bool handled = false; bool handled = false;
if (gui && !handled ) if (gui2 && !handled )
{ {
handled = gui->keyboardCallback(key, state); handled = gui2->keyboardCallback(key, state);
} }
if (!handled && sCurrentDemo) if (!handled && sCurrentDemo)
@@ -226,8 +272,8 @@ static void MyMouseMoveCallback( float x, float y)
bool handled = false; bool handled = false;
if (sCurrentDemo) if (sCurrentDemo)
handled = sCurrentDemo->mouseMoveCallback(x,y); handled = sCurrentDemo->mouseMoveCallback(x,y);
if (!handled && gui) if (!handled && gui2)
handled = gui->mouseMoveCallback(x,y); handled = gui2->mouseMoveCallback(x,y);
if (!handled) if (!handled)
{ {
if (prevMouseMoveCallback) if (prevMouseMoveCallback)
@@ -244,8 +290,8 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
if (sCurrentDemo) if (sCurrentDemo)
handled = sCurrentDemo->mouseButtonCallback(button,state,x,y); handled = sCurrentDemo->mouseButtonCallback(button,state,x,y);
if (!handled && gui) if (!handled && gui2)
handled = gui->mouseButtonCallback(button,state,x,y); handled = gui2->mouseButtonCallback(button,state,x,y);
if (!handled) if (!handled)
{ {
@@ -332,8 +378,11 @@ void selectDemo(int demoIndex)
CommonExampleInterface::CreateFunc* func = gAllExamples->getExampleCreateFunc(demoIndex); CommonExampleInterface::CreateFunc* func = gAllExamples->getExampleCreateFunc(demoIndex);
if (func) if (func)
{
if (s_parameterInterface)
{ {
s_parameterInterface->removeAllParameters(); s_parameterInterface->removeAllParameters();
}
int option = gAllExamples->getExampleOption(demoIndex); int option = gAllExamples->getExampleOption(demoIndex);
s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2); s_guiHelper= new OpenGLGuiHelper(s_app, sUseOpenGL2);
CommonExampleOptions options(s_guiHelper, option); CommonExampleOptions options(s_guiHelper, option);
@@ -341,12 +390,15 @@ void selectDemo(int demoIndex)
sCurrentDemo = (*func)(options); sCurrentDemo = (*func)(options);
if (sCurrentDemo) if (sCurrentDemo)
{ {
if (gui) if (gui2)
{ {
gui->setStatusBarMessage("Status: OK", false); gui2->setStatusBarMessage("Status: OK", false);
} }
b3Printf("Selected demo: %s",gAllExamples->getExampleName(demoIndex)); b3Printf("Selected demo: %s",gAllExamples->getExampleName(demoIndex));
gui->setExampleDescription(gAllExamples->getExampleDescription(demoIndex)); if (gui2)
{
gui2->setExampleDescription(gAllExamples->getExampleDescription(demoIndex));
}
sCurrentDemo->initPhysics(); sCurrentDemo->initPhysics();
if(resetCamera) if(resetCamera)
@@ -437,10 +489,10 @@ void MyComboBoxCallback(int comboId, const char* item)
void MyGuiPrintf(const char* msg) void MyGuiPrintf(const char* msg)
{ {
printf("b3Printf: %s\n",msg); printf("b3Printf: %s\n",msg);
if (gui) if (gui2)
{ {
gui->textOutput(msg); gui2->textOutput(msg);
gui->forceUpdateScrollBars(); gui2->forceUpdateScrollBars();
} }
} }
@@ -449,10 +501,10 @@ void MyGuiPrintf(const char* msg)
void MyStatusBarPrintf(const char* msg) void MyStatusBarPrintf(const char* msg)
{ {
printf("b3Printf: %s\n", msg); printf("b3Printf: %s\n", msg);
if (gui) if (gui2)
{ {
bool isLeft = true; bool isLeft = true;
gui->setStatusBarMessage(msg,isLeft); gui2->setStatusBarMessage(msg,isLeft);
} }
} }
@@ -460,12 +512,12 @@ void MyStatusBarPrintf(const char* msg)
void MyStatusBarError(const char* msg) void MyStatusBarError(const char* msg)
{ {
printf("Warning: %s\n", msg); printf("Warning: %s\n", msg);
if (gui) if (gui2)
{ {
bool isLeft = false; bool isLeft = false;
gui->setStatusBarMessage(msg,isLeft); gui2->setStatusBarMessage(msg,isLeft);
gui->textOutput(msg); gui2->textOutput(msg);
gui->forceUpdateScrollBars(); gui2->forceUpdateScrollBars();
} }
} }
@@ -534,7 +586,7 @@ struct MyMenuItemHander :public Gwen::Event::Handler
{ {
// printf("select %d\n",m_buttonId); // printf("select %d\n",m_buttonId);
sCurrentHightlighted = m_buttonId; sCurrentHightlighted = m_buttonId;
gui->setExampleDescription(gAllExamples->getExampleDescription(sCurrentHightlighted)); gui2->setExampleDescription(gAllExamples->getExampleDescription(sCurrentHightlighted));
} }
void onButtonF(Gwen::Controls::Base* pControl) void onButtonF(Gwen::Controls::Base* pControl)
@@ -549,26 +601,6 @@ struct MyMenuItemHander :public Gwen::Event::Handler
};
#include "Bullet3Common/b3HashMap.h"
struct GL3TexLoader : public MyTextureLoader
{
b3HashMap<b3HashString,GLint> m_hashMap;
virtual void LoadTexture( Gwen::Texture* pTexture )
{
Gwen::String namestr = pTexture->name.Get();
const char* n = namestr.c_str();
GLint* texIdPtr = m_hashMap[n];
if (texIdPtr)
{
pTexture->m_intData = *texIdPtr;
}
}
virtual void FreeTexture( Gwen::Texture* pTexture )
{
}
}; };
void quitCallback() void quitCallback()
@@ -623,7 +655,7 @@ struct QuickCanvas : public Common2dCanvasInterface
m_curNumGraphWindows++; m_curNumGraphWindows++;
MyGraphInput input(gui->getInternalData()); MyGraphInput input(gui2->getInternalData());
input.m_width=width; input.m_width=width;
input.m_height=height; input.m_height=height;
input.m_xPos = 10000;//GUI will clamp it to the right//300; input.m_xPos = 10000;//GUI will clamp it to the right//300;
@@ -669,12 +701,50 @@ struct QuickCanvas : public Common2dCanvasInterface
OpenGLExampleBrowser::OpenGLExampleBrowser(class ExampleEntries* examples) OpenGLExampleBrowser::OpenGLExampleBrowser(class ExampleEntries* examples)
{ {
m_internalData = new OpenGLExampleBrowserInternalData;
gAllExamples = examples; gAllExamples = examples;
} }
OpenGLExampleBrowser::~OpenGLExampleBrowser() OpenGLExampleBrowser::~OpenGLExampleBrowser()
{ {
deleteDemo(); deleteDemo();
for (int i = 0; i < m_internalData->m_nodes.size(); i++)
{
delete m_internalData->m_nodes[i];
}
delete m_internalData->m_handler2;
for (int i = 0; i < m_internalData->m_handlers.size(); i++)
{
delete m_internalData->m_handlers[i];
}
m_internalData->m_handlers.clear();
m_internalData->m_nodes.clear();
delete s_parameterInterface;
s_parameterInterface = 0;
delete s_app->m_2dCanvasInterface;
s_app->m_2dCanvasInterface = 0;
m_internalData->m_gui->exit();
delete m_internalData->m_gui;
delete m_internalData->m_gwenRenderer;
delete m_internalData->m_myTexLoader;
delete m_internalData->m_app;
s_app = 0;
// delete m_internalData->m_profWindow;
delete m_internalData;
gAllExamples = 0; gAllExamples = 0;
} }
@@ -732,11 +802,10 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
char title[1024]; char title[1024];
sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode); sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode);
simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina); simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina);
s_app = simpleApp; s_app = simpleApp;
} }
#endif #endif
m_internalData->m_app = s_app;
char* gVideoFileName = 0; char* gVideoFileName = 0;
args.GetCmdLineArgument("mp4",gVideoFileName); args.GetCmdLineArgument("mp4",gVideoFileName);
#ifndef NO_OPENGL3 #ifndef NO_OPENGL3
@@ -792,41 +861,65 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
assert(glGetError()==GL_NO_ERROR); assert(glGetError()==GL_NO_ERROR);
gui = new GwenUserInterface;
GL3TexLoader* myTexLoader = new GL3TexLoader;
Gwen::Renderer::Base* gwenRenderer = 0;
if (sUseOpenGL2 )
{ {
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); GL3TexLoader* myTexLoader = new GL3TexLoader;
m_internalData->m_myTexLoader = myTexLoader;
sth_stash* fontstash = simpleApp->getFontStash();
if (sUseOpenGL2)
{
m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
} }
#ifndef NO_OPENGL3 #ifndef NO_OPENGL3
else else
{ {
sth_stash* fontstash=simpleApp->getFontStash(); sth_stash* fontstash = simpleApp->getFontStash();
gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader); m_internalData->m_gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer, fontstash, width, height, s_window->getRetinaScale(), myTexLoader);
} }
#endif #endif
gui2 = new GwenUserInterface;
m_internalData->m_gui = gui2;
m_internalData->m_myTexLoader = myTexLoader;
gui2->init(width, height, m_internalData->m_gwenRenderer, s_window->getRetinaScale());
}
//gui = 0;// new GwenUserInterface;
GL3TexLoader* myTexLoader = m_internalData->m_myTexLoader;
// = myTexLoader;
// //
gui->init(width,height,gwenRenderer,s_window->getRetinaScale()); if (gui2)
{
// gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl; // gui->getInternalData()->m_explorerPage
Gwen::Controls::TreeControl* tree = gui2->getInternalData()->m_explorerTreeCtrl;
//gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader); //gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
s_profWindow= setupProfileWindow(gui->getInternalData()); // s_profWindow= setupProfileWindow(gui2->getInternalData());
profileWindowSetVisible(s_profWindow,false); //m_internalData->m_profWindow = s_profWindow;
gui->setFocus(); // profileWindowSetVisible(s_profWindow,false);
gui2->setFocus();
s_parameterInterface = s_app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData()); s_parameterInterface = s_app->m_parameterInterface = new GwenParameterInterface(gui2->getInternalData());
s_app->m_2dCanvasInterface = new QuickCanvas(myTexLoader); s_app->m_2dCanvasInterface = new QuickCanvas(myTexLoader);
@@ -839,7 +932,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
//int curDemo = 0; //int curDemo = 0;
int selectedDemo = 0; int selectedDemo = 0;
Gwen::Controls::TreeNode* curNode = tree; Gwen::Controls::TreeNode* curNode = tree;
MyMenuItemHander* handler2 = new MyMenuItemHander(-1); m_internalData->m_handler2 = new MyMenuItemHander(-1);
char* demoNameFromCommandOption = 0; char* demoNameFromCommandOption = 0;
args.GetCmdLineArgument("start_demo_name", demoNameFromCommandOption); args.GetCmdLineArgument("start_demo_name", demoNameFromCommandOption);
@@ -847,7 +940,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
selectedDemo = -1; selectedDemo = -1;
} }
tree->onReturnKeyDown.Add(handler2, &MyMenuItemHander::onButtonD); tree->onReturnKeyDown.Add(m_internalData->m_handler2, &MyMenuItemHander::onButtonD);
int firstAvailableDemoIndex=-1; int firstAvailableDemoIndex=-1;
Gwen::Controls::TreeNode* firstNode=0; Gwen::Controls::TreeNode* firstNode=0;
@@ -894,13 +987,18 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
} }
} }
#if 1
MyMenuItemHander* handler = new MyMenuItemHander(d); MyMenuItemHander* handler = new MyMenuItemHander(d);
m_internalData->m_handlers.push_back(handler);
pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA); pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA);
pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB); pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB);
pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC); pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC);
pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE); pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE);
pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG); pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG);
pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF); pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF);
#endif
// pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD);
// pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD);
// pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD);
@@ -910,6 +1008,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
else else
{ {
curNode = tree->AddNode(nodeUText); curNode = tree->AddNode(nodeUText);
m_internalData->m_nodes.push_back(curNode);
} }
} }
@@ -928,6 +1027,9 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
} }
} }
free(demoNameFromCommandOption);
demoNameFromCommandOption = 0;
btAssert(sCurrentDemo!=0); btAssert(sCurrentDemo!=0);
if (sCurrentDemo==0) if (sCurrentDemo==0)
{ {
@@ -935,8 +1037,10 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
exit(0); exit(0);
} }
gui->registerFileOpenCallback(fileOpenCallback); gui2->registerFileOpenCallback(fileOpenCallback);
gui->registerQuitCallback(quitCallback); gui2->registerQuitCallback(quitCallback);
}
return true; return true;
} }
@@ -1044,7 +1148,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
{ {
if (s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera()) if (gui2 && s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera())
{ {
char msg[1024]; char msg[1024];
float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance(); float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance();
@@ -1053,7 +1157,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
float camTarget[3]; float camTarget[3];
s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget); s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget);
sprintf(msg,"dist=%f, pitch=%f, yaw=%f,target=%f,%f,%f", camDist,pitch,yaw,camTarget[0],camTarget[1],camTarget[2]); sprintf(msg,"dist=%f, pitch=%f, yaw=%f,target=%f,%f,%f", camDist,pitch,yaw,camTarget[0],camTarget[1],camTarget[2]);
gui->setStatusBarMessage(msg, true); gui2->setStatusBarMessage(msg, true);
} }
} }
@@ -1061,16 +1165,24 @@ void OpenGLExampleBrowser::update(float deltaTime)
static int toggle = 1; static int toggle = 1;
if (renderGui) if (renderGui)
{ {
if (!pauseSimulation) // if (!pauseSimulation)
processProfileData(s_profWindow,false); // processProfileData(s_profWindow,false);
if (sUseOpenGL2) if (sUseOpenGL2)
{ {
saveOpenGLState(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight()); saveOpenGLState(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
} }
BT_PROFILE("Draw Gwen GUI"); BT_PROFILE("Draw Gwen GUI");
gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight()); if (m_internalData->m_gui)
{
m_internalData->m_gui->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
}
if (gui2)
{
gui2->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
}
if (sUseOpenGL2) if (sUseOpenGL2)
{ {
restoreOpenGLState(); restoreOpenGLState();
@@ -1084,14 +1196,20 @@ void OpenGLExampleBrowser::update(float deltaTime)
toggle=1-toggle; toggle=1-toggle;
{ {
BT_PROFILE("Sync Parameters"); BT_PROFILE("Sync Parameters");
if (s_parameterInterface)
{
s_parameterInterface->syncParameters(); s_parameterInterface->syncParameters();
} }
}
{ {
BT_PROFILE("Swap Buffers"); BT_PROFILE("Swap Buffers");
s_app->swapBuffer(); s_app->swapBuffer();
} }
gui->forceUpdateScrollBars(); if (gui2)
{
gui2->forceUpdateScrollBars();
}
} }

View File

@@ -5,6 +5,9 @@
class OpenGLExampleBrowser : public ExampleBrowserInterface class OpenGLExampleBrowser : public ExampleBrowserInterface
{ {
struct OpenGLExampleBrowserInternalData* m_internalData;
public: public:
OpenGLExampleBrowser(class ExampleEntries* examples); OpenGLExampleBrowser(class ExampleEntries* examples);

View File

@@ -167,6 +167,7 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2)
OpenGLGuiHelper::~OpenGLGuiHelper() OpenGLGuiHelper::~OpenGLGuiHelper()
{ {
delete m_data->m_debugDraw;
delete m_data->m_gl2ShapeDrawer; delete m_data->m_gl2ShapeDrawer;
delete m_data; delete m_data;
} }

View File

@@ -1,3 +1,4 @@
#include "C:\develop\visual_leak_detector\vld-2.5\vld-2.5\src\vld.h"
#include "OpenGLExampleBrowser.h" #include "OpenGLExampleBrowser.h"
@@ -19,7 +20,8 @@
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
b3CommandLineArgs args(argc,argv); {
b3CommandLineArgs args(argc, argv);
b3Clock clock; b3Clock clock;
@@ -27,18 +29,18 @@ int main(int argc, char* argv[])
examples.initExampleEntries(); examples.initExampleEntries();
OpenGLExampleBrowser* exampleBrowser = new OpenGLExampleBrowser(&examples); OpenGLExampleBrowser* exampleBrowser = new OpenGLExampleBrowser(&examples);
bool init = exampleBrowser->init(argc,argv); bool init = exampleBrowser->init(argc, argv);
exampleBrowser->registerFileImporter(".urdf",ImportURDFCreateFunc); exampleBrowser->registerFileImporter(".urdf", ImportURDFCreateFunc);
exampleBrowser->registerFileImporter(".sdf",ImportSDFCreateFunc); exampleBrowser->registerFileImporter(".sdf", ImportSDFCreateFunc);
exampleBrowser->registerFileImporter(".obj",ImportObjCreateFunc); exampleBrowser->registerFileImporter(".obj", ImportObjCreateFunc);
exampleBrowser->registerFileImporter(".stl",ImportSTLCreateFunc); exampleBrowser->registerFileImporter(".stl", ImportSTLCreateFunc);
clock.reset(); clock.reset();
if (init) if (init)
{ {
do do
{ {
float deltaTimeInSeconds = clock.getTimeMicroseconds()/1000000.f; float deltaTimeInSeconds = clock.getTimeMicroseconds() / 1000000.f;
clock.reset(); clock.reset();
exampleBrowser->update(deltaTimeInSeconds); exampleBrowser->update(deltaTimeInSeconds);
@@ -46,6 +48,6 @@ int main(int argc, char* argv[])
} }
delete exampleBrowser; delete exampleBrowser;
}
return 0; return 0;
} }

View File

@@ -1058,6 +1058,7 @@ btCollisionShape* BulletURDFImporter::getAllocatedCollisionShape(int index)
{ {
const UrdfCollision& col = link->m_collisionArray[v]; const UrdfCollision& col = link->m_collisionArray[v];
btCollisionShape* childShape = convertURDFToCollisionShape(&col ,pathPrefix); btCollisionShape* childShape = convertURDFToCollisionShape(&col ,pathPrefix);
m_data->m_allocatedCollisionShapes.push_back(childShape);
if (childShape) if (childShape)
{ {

View File

@@ -61,7 +61,9 @@ static bool parseVector4(btVector4& vec4, const std::string& vector_str)
vec4.setZero(); vec4.setZero();
btArray<std::string> pieces; btArray<std::string> pieces;
btArray<float> rgba; btArray<float> rgba;
urdfStringSplit(pieces, vector_str, urdfIsAnyOf(" ")); btAlignedObjectArray<std::string> strArray;
urdfIsAnyOf(" ", strArray);
urdfStringSplit(pieces, vector_str, strArray);
for (int i = 0; i < pieces.size(); ++i) for (int i = 0; i < pieces.size(); ++i)
{ {
if (!pieces[i].empty()) if (!pieces[i].empty())
@@ -82,7 +84,9 @@ static bool parseVector3(btVector3& vec3, const std::string& vector_str, ErrorLo
vec3.setZero(); vec3.setZero();
btArray<std::string> pieces; btArray<std::string> pieces;
btArray<float> rgba; btArray<float> rgba;
urdfStringSplit(pieces, vector_str, urdfIsAnyOf(" ")); btAlignedObjectArray<std::string> strArray;
urdfIsAnyOf(" ", strArray);
urdfStringSplit(pieces, vector_str, strArray);
for (int i = 0; i < pieces.size(); ++i) for (int i = 0; i < pieces.size(); ++i)
{ {
if (!pieces[i].empty()) if (!pieces[i].empty())

View File

@@ -8,7 +8,7 @@
#include "urdfStringSplit.h" #include "urdfStringSplit.h"
void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::string& vector_str, btAlignedObjectArray<std::string> separators) void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::string& vector_str, const btAlignedObjectArray<std::string>& separators)
{ {
assert(separators.size()==1); assert(separators.size()==1);
if (separators.size()==1) if (separators.size()==1)
@@ -20,9 +20,8 @@ void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::strin
urdfStrArrayFree(strArray); urdfStrArrayFree(strArray);
} }
} }
btAlignedObjectArray<std::string> urdfIsAnyOf(const char* seps) void urdfIsAnyOf(const char* seps, btAlignedObjectArray<std::string>& strArray)
{ {
btAlignedObjectArray<std::string> strArray;
int numSeps = strlen(seps); int numSeps = strlen(seps);
for (int i=0;i<numSeps;i++) for (int i=0;i<numSeps;i++)
@@ -32,8 +31,6 @@ void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::strin
sep2[0] = seps[i]; sep2[0] = seps[i];
strArray.push_back(sep2); strArray.push_back(sep2);
} }
return strArray;
} }

View File

@@ -7,9 +7,9 @@
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::string& vector_str, btAlignedObjectArray<std::string> separators); void urdfStringSplit( btAlignedObjectArray<std::string>&pieces, const std::string& vector_str, const btAlignedObjectArray<std::string>& separators);
btAlignedObjectArray<std::string> urdfIsAnyOf(const char* seps); void urdfIsAnyOf(const char* seps, btAlignedObjectArray<std::string>& strArray);
///The string split C code is by Lars Wirzenius ///The string split C code is by Lars Wirzenius
///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char ///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char

View File

@@ -73,6 +73,7 @@ class InverseDynamicsExample : public CommonMultiBodyBase
{ {
btInverseDynamicsExampleOptions m_option; btInverseDynamicsExampleOptions m_option;
btMultiBody* m_multiBody; btMultiBody* m_multiBody;
btAlignedObjectArray<btCollisionShape*> m_allocatedShapes;
btInverseDynamics::MultiBodyTree *m_inverseModel; btInverseDynamics::MultiBodyTree *m_inverseModel;
TimeSeriesCanvas* m_timeSeriesCanvas; TimeSeriesCanvas* m_timeSeriesCanvas;
public: public:
@@ -105,7 +106,13 @@ InverseDynamicsExample::InverseDynamicsExample(struct GUIHelperInterface* helper
InverseDynamicsExample::~InverseDynamicsExample() InverseDynamicsExample::~InverseDynamicsExample()
{ {
delete m_multiBody; delete m_multiBody;
for (int i = 0; i < m_allocatedShapes.size(); i++)
{
delete m_allocatedShapes[i];
}
m_allocatedShapes.resize(0);
delete m_inverseModel; delete m_inverseModel;
delete m_timeSeriesCanvas; delete m_timeSeriesCanvas;
} }
@@ -166,6 +173,10 @@ void InverseDynamicsExample::initPhysics()
btTransform identityTrans; btTransform identityTrans;
identityTrans.setIdentity(); identityTrans.setIdentity();
ConvertURDF2Bullet(u2b,creation, identityTrans,m_dynamicsWorld,true,u2b.getPathPrefix()); ConvertURDF2Bullet(u2b,creation, identityTrans,m_dynamicsWorld,true,u2b.getPathPrefix());
for (int i = 0; i < u2b.getNumAllocatedCollisionShapes(); i++)
{
m_allocatedShapes.push_back(u2b.getAllocatedCollisionShape(i));
}
m_multiBody = creation.getBulletMultiBody(); m_multiBody = creation.getBulletMultiBody();
if (m_multiBody) if (m_multiBody)
{ {

View File

@@ -655,8 +655,9 @@ SimpleOpenGL3App::~SimpleOpenGL3App()
delete m_primRenderer ; delete m_primRenderer ;
sth_delete(m_data->m_fontStash); sth_delete(m_data->m_fontStash);
delete m_data->m_renderCallbacks; delete m_data->m_renderCallbacks;
m_window->closeWindow();
TwDeleteDefaultFonts(); TwDeleteDefaultFonts();
m_window->closeWindow();
delete m_window; delete m_window;
delete m_data ; delete m_data ;
} }

View File

@@ -4883,18 +4883,33 @@ static const unsigned char s_FontFixed1[] = {
void TwGenerateDefaultFonts() void TwGenerateDefaultFonts()
{ {
if (g_DefaultSmallFont == 0)
{
g_DefaultSmallFont = TwGenerateFont(s_Font0, FONT0_BM_W, FONT0_BM_H); g_DefaultSmallFont = TwGenerateFont(s_Font0, FONT0_BM_W, FONT0_BM_H);
assert(g_DefaultSmallFont && g_DefaultSmallFont->m_NbCharRead==224); assert(g_DefaultSmallFont && g_DefaultSmallFont->m_NbCharRead == 224);
}
if (g_DefaultNormalFont == 0)
{
g_DefaultNormalFont = TwGenerateFont(s_Font1, FONT1_BM_W, FONT1_BM_H); g_DefaultNormalFont = TwGenerateFont(s_Font1, FONT1_BM_W, FONT1_BM_H);
assert(g_DefaultNormalFont && g_DefaultNormalFont->m_NbCharRead==224); assert(g_DefaultNormalFont && g_DefaultNormalFont->m_NbCharRead == 224);
}
if (g_DefaultNormalFontAA == 0)
{
g_DefaultNormalFontAA = TwGenerateFont(s_Font1AA, FONT1AA_BM_W, FONT1AA_BM_H); g_DefaultNormalFontAA = TwGenerateFont(s_Font1AA, FONT1AA_BM_W, FONT1AA_BM_H);
assert(g_DefaultNormalFontAA && g_DefaultNormalFontAA->m_NbCharRead==224); assert(g_DefaultNormalFontAA && g_DefaultNormalFontAA->m_NbCharRead == 224);
}
if (g_DefaultLargeFont == 0)
{
g_DefaultLargeFont = TwGenerateFont(s_Font2AA, FONT2AA_BM_W, FONT2AA_BM_H); g_DefaultLargeFont = TwGenerateFont(s_Font2AA, FONT2AA_BM_W, FONT2AA_BM_H);
assert(g_DefaultLargeFont && g_DefaultLargeFont->m_NbCharRead==224); assert(g_DefaultLargeFont && g_DefaultLargeFont->m_NbCharRead == 224);
}
if (g_DefaultFixed1Font == 0)
{
g_DefaultFixed1Font = TwGenerateFont(s_FontFixed1, FONTFIXED1_BM_W, FONTFIXED1_BM_H); g_DefaultFixed1Font = TwGenerateFont(s_FontFixed1, FONTFIXED1_BM_W, FONTFIXED1_BM_H);
assert(g_DefaultFixed1Font && g_DefaultFixed1Font->m_NbCharRead==224); assert(g_DefaultFixed1Font && g_DefaultFixed1Font->m_NbCharRead == 224);
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
#include "OpenGLWindow/SimpleOpenGL3App.h" #include "OpenGLWindow/SimpleOpenGL3App.h"
#include "Bullet3Common/b3Quaternion.h" #include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3CommandLineArgs.h" #include "Bullet3Common/b3CommandLineArgs.h"
@@ -59,14 +61,15 @@ void MyKeyboardCallback(int keycode, int state)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
b3CommandLineArgs myArgs(argc,argv); {
b3CommandLineArgs myArgs(argc, argv);
SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App",gWidth,gHeight,true); SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App", gWidth, gHeight, true);
app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13); app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13);
app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0); app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0);
app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition(0,0,0); app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition(0, 0, 0);
sOldKeyboardCB = app->m_window->getKeyboardCallback(); sOldKeyboardCB = app->m_window->getKeyboardCallback();
app->m_window->setKeyboardCallback(MyKeyboardCallback); app->m_window->setKeyboardCallback(MyKeyboardCallback);
sOldMouseMoveCB = app->m_window->getMouseMoveCallback(); sOldMouseMoveCB = app->m_window->getMouseMoveCallback();
@@ -79,28 +82,28 @@ int main(int argc, char* argv[])
app->m_window->setResizeCallback(MyResizeCallback); app->m_window->setResizeCallback(MyResizeCallback);
myArgs.GetCmdLineArgument("mp4_file",gVideoFileName); myArgs.GetCmdLineArgument("mp4_file", gVideoFileName);
if (gVideoFileName) if (gVideoFileName)
app->dumpFramesToVideo(gVideoFileName); app->dumpFramesToVideo(gVideoFileName);
myArgs.GetCmdLineArgument("png_file",gPngFileName); myArgs.GetCmdLineArgument("png_file", gPngFileName);
char fileName[1024]; char fileName[1024];
int textureWidth = 128; int textureWidth = 128;
int textureHeight = 128; int textureHeight = 128;
unsigned char* image=new unsigned char[textureWidth*textureHeight*4]; unsigned char* image = new unsigned char[textureWidth*textureHeight * 4];
int textureHandle = app->m_renderer->registerTexture(image,textureWidth,textureHeight); int textureHandle = app->m_renderer->registerTexture(image, textureWidth, textureHeight);
int cubeIndex = app->registerCubeShape(1,1,1); int cubeIndex = app->registerCubeShape(1, 1, 1);
b3Vector3 pos = b3MakeVector3(0,0,0); b3Vector3 pos = b3MakeVector3(0, 0, 0);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0, 0, 0, 1);
b3Vector3 color=b3MakeVector3(1,0,0); b3Vector3 color = b3MakeVector3(1, 0, 0);
b3Vector3 scaling=b3MakeVector3 (1,1,1); b3Vector3 scaling = b3MakeVector3 (1, 1, 1);
app->m_renderer->registerGraphicsInstance(cubeIndex,pos,orn,color,scaling); app->m_renderer->registerGraphicsInstance(cubeIndex, pos, orn, color, scaling);
app->m_renderer->writeTransforms(); app->m_renderer->writeTransforms();
do do
@@ -109,33 +112,33 @@ int main(int argc, char* argv[])
frameCount++; frameCount++;
if (gPngFileName) if (gPngFileName)
{ {
printf("gPngFileName=%s\n",gPngFileName); printf("gPngFileName=%s\n", gPngFileName);
sprintf(fileName,"%s%d.png",gPngFileName,frameCount++); sprintf(fileName, "%s%d.png", gPngFileName, frameCount++);
app->dumpNextFrameToPng(fileName); app->dumpNextFrameToPng(fileName);
} }
//update the texels of the texture using a simple pattern, animated using frame index //update the texels of the texture using a simple pattern, animated using frame index
for(int y=0;y<textureHeight;++y) for (int y = 0; y < textureHeight; ++y)
{ {
const int t=(y+frameCount)>>4; const int t = (y + frameCount) >> 4;
unsigned char* pi=image+y*textureWidth*3; unsigned char* pi = image + y*textureWidth * 3;
for(int x=0;x<textureWidth;++x) for (int x = 0; x < textureWidth; ++x)
{ {
const int s=x>>4; const int s = x >> 4;
const unsigned char b=180; const unsigned char b = 180;
unsigned char c=b+((s+(t&1))&1)*(255-b); unsigned char c = b + ((s + (t & 1)) & 1)*(255 - b);
pi[0]=pi[1]=pi[2]=pi[3]=c;pi+=3; pi[0] = pi[1] = pi[2] = pi[3] = c; pi += 3;
} }
} }
app->m_renderer->activateTexture(textureHandle); app->m_renderer->activateTexture(textureHandle);
app->m_renderer->updateTexture(textureHandle,image); app->m_renderer->updateTexture(textureHandle, image);
float color[4] = {255,1,1,1}; float color[4] = { 255, 1, 1, 1 };
app->m_primRenderer->drawTexturedRect(100,200,gWidth/2-50,gHeight/2-50,color,0,0,1,1,true); app->m_primRenderer->drawTexturedRect(100, 200, gWidth / 2 - 50, gHeight / 2 - 50, color, 0, 0, 1, 1, true);
app->m_instancingRenderer->init(); app->m_instancingRenderer->init();
@@ -144,9 +147,9 @@ int main(int argc, char* argv[])
app->m_renderer->renderScene(); app->m_renderer->renderScene();
app->drawGrid(); app->drawGrid();
char bla[1024]; char bla[1024];
sprintf(bla,"Simple test frame %d", frameCount); sprintf(bla, "Simple test frame %d", frameCount);
app->drawText(bla,10,10); app->drawText(bla, 10, 10);
app->swapBuffer(); app->swapBuffer();
} while (!app->m_window->requestedExit()); } while (!app->m_window->requestedExit());
@@ -155,5 +158,6 @@ int main(int argc, char* argv[])
delete app; delete app;
delete[] image; delete[] image;
}
return 0; return 0;
} }

View File

@@ -28,22 +28,22 @@ subject to the following restrictions:
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
{
DummyGUIHelper noGfx; DummyGUIHelper noGfx;
CommonExampleOptions options(&noGfx); CommonExampleOptions options(&noGfx);
CommonExampleInterface* example = StandaloneExampleCreateFunc(options); CommonExampleInterface* example = StandaloneExampleCreateFunc(options);
example->initPhysics(); example->initPhysics();
for (int i=0;i<1000;i++) for (int i = 0; i < 1000; i++)
{ {
printf("Simulating step %d\n",i); printf("Simulating step %d\n", i);
example->stepSimulation(1.f/60.f); example->stepSimulation(1.f / 60.f);
} }
example->exitPhysics(); example->exitPhysics();
delete example; delete example;
}
return 0; return 0;
} }