OpenGLExampleBrowser.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. #include "OpenGLExampleBrowser.h"
  2. #include "LinearMath/btQuickprof.h"
  3. #include "../OpenGLWindow/OpenGLInclude.h"
  4. #include "../OpenGLWindow/SimpleOpenGL2App.h"
  5. #ifndef NO_OPENGL3
  6. #include "../OpenGLWindow/SimpleOpenGL3App.h"
  7. #endif
  8. #include "../CommonInterfaces/CommonRenderInterface.h"
  9. #ifdef __APPLE__
  10. #include "../OpenGLWindow/MacOpenGLWindow.h"
  11. #else
  12. #ifdef _WIN32
  13. #include "../OpenGLWindow/Win32OpenGLWindow.h"
  14. #else
  15. //let's cross the fingers it is Linux/X11
  16. #ifdef BT_USE_EGL
  17. #include "../OpenGLWindow/EGLOpenGLWindow.h"
  18. #else
  19. #include "../OpenGLWindow/X11OpenGLWindow.h"
  20. #endif //BT_USE_EGL
  21. #endif //_WIN32
  22. #endif //__APPLE__
  23. #include "../ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.h"
  24. #include "LinearMath/btThreads.h"
  25. #include "Bullet3Common/b3Vector3.h"
  26. #include "assert.h"
  27. #include <stdio.h>
  28. #include "GwenGUISupport/gwenInternalData.h"
  29. #include "GwenGUISupport/gwenUserInterface.h"
  30. #include "../Utils/b3Clock.h"
  31. #include "../Utils/ChromeTraceUtil.h"
  32. #include "GwenGUISupport/GwenParameterInterface.h"
  33. #ifndef BT_NO_PROFILE
  34. #include "GwenGUISupport/GwenProfileWindow.h"
  35. #endif
  36. #include "GwenGUISupport/GwenTextureWindow.h"
  37. #include "GwenGUISupport/GraphingTexture.h"
  38. #include "../CommonInterfaces/Common2dCanvasInterface.h"
  39. #include "../CommonInterfaces/CommonExampleInterface.h"
  40. #include "Bullet3Common/b3CommandLineArgs.h"
  41. #include "../OpenGLWindow/SimpleCamera.h"
  42. #include "../OpenGLWindow/SimpleOpenGL2Renderer.h"
  43. #include "ExampleEntries.h"
  44. #include "OpenGLGuiHelper.h"
  45. #include "Bullet3Common/b3FileUtils.h"
  46. #include "LinearMath/btIDebugDraw.h"
  47. //quick test for file import, @todo(erwincoumans) make it more general and add other file formats
  48. #include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
  49. #include "../Importers/ImportBullet/SerializeSetup.h"
  50. #include "Bullet3Common/b3HashMap.h"
  51. struct GL3TexLoader : public MyTextureLoader
  52. {
  53. b3HashMap<b3HashString, GLint> m_hashMap;
  54. virtual void LoadTexture(Gwen::Texture* pTexture)
  55. {
  56. Gwen::String namestr = pTexture->name.Get();
  57. const char* n = namestr.c_str();
  58. GLint* texIdPtr = m_hashMap[n];
  59. if (texIdPtr)
  60. {
  61. pTexture->m_intData = *texIdPtr;
  62. }
  63. }
  64. virtual void FreeTexture(Gwen::Texture* pTexture)
  65. {
  66. }
  67. };
  68. struct OpenGLExampleBrowserInternalData
  69. {
  70. Gwen::Renderer::Base* m_gwenRenderer;
  71. CommonGraphicsApp* m_app;
  72. #ifndef BT_NO_PROFILE
  73. MyProfileWindow* m_profWindow;
  74. #endif //BT_NO_PROFILE
  75. btAlignedObjectArray<Gwen::Controls::TreeNode*> m_nodes;
  76. GwenUserInterface* m_gui;
  77. GL3TexLoader* m_myTexLoader;
  78. struct MyMenuItemHander* m_handler2;
  79. btAlignedObjectArray<MyMenuItemHander*> m_handlers;
  80. OpenGLExampleBrowserInternalData()
  81. : m_gwenRenderer(0),
  82. m_app(0),
  83. // m_profWindow(0),
  84. m_gui(0),
  85. m_myTexLoader(0),
  86. m_handler2(0)
  87. {
  88. }
  89. };
  90. static CommonGraphicsApp* s_app = 0;
  91. static CommonWindowInterface* s_window = 0;
  92. static CommonParameterInterface* s_parameterInterface = 0;
  93. static CommonRenderInterface* s_instancingRenderer = 0;
  94. static OpenGLGuiHelper* s_guiHelper = 0;
  95. #ifndef BT_NO_PROFILE
  96. static MyProfileWindow* s_profWindow = 0;
  97. #endif //BT_NO_PROFILE
  98. static SharedMemoryInterface* sSharedMem = 0;
  99. #define DEMO_SELECTION_COMBOBOX 13
  100. const char* startFileName = "0_Bullet3Demo.txt";
  101. char staticPngFileName[1024];
  102. //static GwenUserInterface* gui = 0;
  103. static GwenUserInterface* gui2 = 0;
  104. static int sCurrentDemoIndex = -1;
  105. static int sCurrentHightlighted = 0;
  106. static CommonExampleInterface* sCurrentDemo = 0;
  107. static b3AlignedObjectArray<const char*> allNames;
  108. static float gFixedTimeStep = 0;
  109. bool gAllowRetina = true;
  110. bool gDisableDemoSelection = false;
  111. int gRenderDevice = -1;
  112. int gWindowBackend = 0;
  113. static class ExampleEntries* gAllExamples = 0;
  114. bool sUseOpenGL2 = false;
  115. #ifndef USE_OPENGL3
  116. extern bool useShadowMap;
  117. #endif
  118. bool visualWireframe = false;
  119. static bool renderVisualGeometry = true;
  120. static bool renderGrid = true;
  121. static bool gEnableRenderLoop = true;
  122. bool renderGui = true;
  123. static bool enable_experimental_opencl = false;
  124. static bool gEnableDefaultKeyboardShortcuts = true;
  125. static bool gEnableDefaultMousePicking = true;
  126. int gDebugDrawFlags = 0;
  127. static bool pauseSimulation = false;
  128. static bool singleStepSimulation = false;
  129. int midiBaseIndex = 176;
  130. extern bool gDisableDeactivation;
  131. int gSharedMemoryKey = -1;
  132. ///some quick test variable for the OpenCL examples
  133. int gPreferredOpenCLDeviceIndex = -1;
  134. int gPreferredOpenCLPlatformIndex = -1;
  135. int gGpuArraySizeX = 45;
  136. int gGpuArraySizeY = 55;
  137. int gGpuArraySizeZ = 45;
  138. //#include <float.h>
  139. //unsigned int fp_control_state = _controlfp(_EM_INEXACT, _MCW_EM);
  140. void deleteDemo()
  141. {
  142. if (sCurrentDemo)
  143. {
  144. sCurrentDemo->exitPhysics();
  145. s_instancingRenderer->removeAllInstances();
  146. delete sCurrentDemo;
  147. sCurrentDemo = 0;
  148. delete s_guiHelper;
  149. s_guiHelper = 0;
  150. // CProfileManager::CleanupMemory();
  151. }
  152. }
  153. const char* gPngFileName = 0;
  154. int gPngSkipFrames = 0;
  155. b3KeyboardCallback prevKeyboardCallback = 0;
  156. void MyKeyboardCallback(int key, int state)
  157. {
  158. //b3Printf("key=%d, state=%d", key, state);
  159. bool handled = false;
  160. if (renderGui)
  161. {
  162. if (gui2 && !handled)
  163. {
  164. handled = gui2->keyboardCallback(key, state);
  165. }
  166. }
  167. if (!handled && sCurrentDemo)
  168. {
  169. handled = sCurrentDemo->keyboardCallback(key, state);
  170. }
  171. //checkout: is it desired to ignore keys, if the demo already handles them?
  172. //if (handled)
  173. // return;
  174. if (gEnableDefaultKeyboardShortcuts)
  175. {
  176. if (key == 'a' && state)
  177. {
  178. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawAabb;
  179. }
  180. if (key == 'c' && state)
  181. {
  182. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawContactPoints;
  183. }
  184. if (key == 'd' && state)
  185. {
  186. gDebugDrawFlags ^= btIDebugDraw::DBG_NoDeactivation;
  187. gDisableDeactivation = ((gDebugDrawFlags & btIDebugDraw::DBG_NoDeactivation) != 0);
  188. }
  189. if (key == 'j' && state)
  190. {
  191. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawFrames;
  192. }
  193. if (key == 'k' && state)
  194. {
  195. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawConstraints;
  196. }
  197. if (key == 'l' && state)
  198. {
  199. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawConstraintLimits;
  200. }
  201. if (key == 'w' && state)
  202. {
  203. visualWireframe = !visualWireframe;
  204. gDebugDrawFlags ^= btIDebugDraw::DBG_DrawWireframe;
  205. }
  206. if (key == 'v' && state)
  207. {
  208. renderVisualGeometry = !renderVisualGeometry;
  209. }
  210. if (key == 'g' && state)
  211. {
  212. renderGrid = !renderGrid;
  213. renderGui = !renderGui;
  214. }
  215. if (key == 'i' && state)
  216. {
  217. pauseSimulation = !pauseSimulation;
  218. }
  219. if (key == 'o' && state)
  220. {
  221. singleStepSimulation = true;
  222. }
  223. if (key == 'p')
  224. {
  225. if (state)
  226. {
  227. b3ChromeUtilsStartTimings();
  228. }
  229. else
  230. {
  231. #ifdef _WIN32
  232. b3ChromeUtilsStopTimingsAndWriteJsonFile("timings");
  233. #else
  234. b3ChromeUtilsStopTimingsAndWriteJsonFile("/tmp/timings");
  235. #endif
  236. }
  237. }
  238. #ifndef NO_OPENGL3
  239. if (key == 's' && state)
  240. {
  241. useShadowMap = !useShadowMap;
  242. }
  243. #endif
  244. if (key == B3G_F1)
  245. {
  246. static int count = 0;
  247. if (state)
  248. {
  249. b3Printf("F1 pressed %d", count++);
  250. if (gPngFileName)
  251. {
  252. b3Printf("disable image dump");
  253. gPngFileName = 0;
  254. }
  255. else
  256. {
  257. gPngFileName = gAllExamples->getExampleName(sCurrentDemoIndex);
  258. b3Printf("enable image dump %s", gPngFileName);
  259. }
  260. }
  261. else
  262. {
  263. b3Printf("F1 released %d", count++);
  264. }
  265. }
  266. }
  267. if (key == B3G_ESCAPE && s_window)
  268. {
  269. s_window->setRequestExit();
  270. }
  271. if (prevKeyboardCallback)
  272. prevKeyboardCallback(key, state);
  273. }
  274. b3MouseMoveCallback prevMouseMoveCallback = 0;
  275. static void MyMouseMoveCallback(float x, float y)
  276. {
  277. bool handled = false;
  278. if (sCurrentDemo)
  279. handled = sCurrentDemo->mouseMoveCallback(x, y);
  280. if (renderGui)
  281. {
  282. if (!handled && gui2)
  283. handled = gui2->mouseMoveCallback(x, y);
  284. }
  285. if (!handled)
  286. {
  287. if (prevMouseMoveCallback)
  288. prevMouseMoveCallback(x, y);
  289. }
  290. }
  291. b3MouseButtonCallback prevMouseButtonCallback = 0;
  292. static void MyMouseButtonCallback(int button, int state, float x, float y)
  293. {
  294. bool handled = false;
  295. //try picking first
  296. if (sCurrentDemo)
  297. handled = sCurrentDemo->mouseButtonCallback(button, state, x, y);
  298. if (renderGui)
  299. {
  300. if (!handled && gui2)
  301. handled = gui2->mouseButtonCallback(button, state, x, y);
  302. }
  303. if (!handled)
  304. {
  305. if (prevMouseButtonCallback)
  306. prevMouseButtonCallback(button, state, x, y);
  307. }
  308. // b3DefaultMouseButtonCallback(button,state,x,y);
  309. }
  310. #include <string.h>
  311. struct FileImporterByExtension
  312. {
  313. std::string m_extension;
  314. CommonExampleInterface::CreateFunc* m_createFunc;
  315. };
  316. static btAlignedObjectArray<FileImporterByExtension> gFileImporterByExtension;
  317. void OpenGLExampleBrowser::registerFileImporter(const char* extension, CommonExampleInterface::CreateFunc* createFunc)
  318. {
  319. FileImporterByExtension fi;
  320. fi.m_extension = extension;
  321. fi.m_createFunc = createFunc;
  322. gFileImporterByExtension.push_back(fi);
  323. }
  324. #include "../SharedMemory/SharedMemoryPublic.h"
  325. void OpenGLExampleBrowserVisualizerFlagCallback(int flag, bool enable)
  326. {
  327. if (flag == COV_ENABLE_Y_AXIS_UP)
  328. {
  329. //either Y = up or Z
  330. int upAxis = enable ? 1 : 2;
  331. s_app->setUpAxis(upAxis);
  332. }
  333. if (flag == COV_ENABLE_RENDERING)
  334. {
  335. gEnableRenderLoop = (enable != 0);
  336. }
  337. if (flag == COV_ENABLE_SINGLE_STEP_RENDERING)
  338. {
  339. if (enable)
  340. {
  341. gEnableRenderLoop = false;
  342. singleStepSimulation = true;
  343. }
  344. else
  345. {
  346. gEnableRenderLoop = true;
  347. singleStepSimulation = false;
  348. }
  349. }
  350. if (flag == COV_ENABLE_SHADOWS)
  351. {
  352. useShadowMap = enable;
  353. }
  354. if (flag == COV_ENABLE_GUI)
  355. {
  356. renderGui = enable;
  357. renderGrid = enable;
  358. }
  359. if (flag == COV_ENABLE_KEYBOARD_SHORTCUTS)
  360. {
  361. gEnableDefaultKeyboardShortcuts = enable;
  362. }
  363. if (flag == COV_ENABLE_MOUSE_PICKING)
  364. {
  365. gEnableDefaultMousePicking = enable;
  366. }
  367. if (flag == COV_ENABLE_WIREFRAME)
  368. {
  369. visualWireframe = enable;
  370. if (visualWireframe)
  371. {
  372. gDebugDrawFlags |= btIDebugDraw::DBG_DrawWireframe;
  373. }
  374. else
  375. {
  376. gDebugDrawFlags &= ~btIDebugDraw::DBG_DrawWireframe;
  377. }
  378. }
  379. }
  380. void openFileDemo(const char* filename)
  381. {
  382. deleteDemo();
  383. s_guiHelper = new OpenGLGuiHelper(s_app, sUseOpenGL2);
  384. s_guiHelper->setVisualizerFlagCallback(OpenGLExampleBrowserVisualizerFlagCallback);
  385. s_parameterInterface->removeAllParameters();
  386. CommonExampleOptions options(s_guiHelper, 1);
  387. options.m_fileName = filename;
  388. char fullPath[1024];
  389. sprintf(fullPath, "%s", filename);
  390. b3FileUtils::toLower(fullPath);
  391. for (int i = 0; i < gFileImporterByExtension.size(); i++)
  392. {
  393. if (strstr(fullPath, gFileImporterByExtension[i].m_extension.c_str()))
  394. {
  395. sCurrentDemo = gFileImporterByExtension[i].m_createFunc(options);
  396. }
  397. }
  398. if (sCurrentDemo)
  399. {
  400. sCurrentDemo->initPhysics();
  401. sCurrentDemo->resetCamera();
  402. }
  403. }
  404. void selectDemo(int demoIndex)
  405. {
  406. bool resetCamera = (sCurrentDemoIndex != demoIndex);
  407. sCurrentDemoIndex = demoIndex;
  408. sCurrentHightlighted = demoIndex;
  409. int numDemos = gAllExamples->getNumRegisteredExamples();
  410. if (demoIndex > numDemos)
  411. {
  412. demoIndex = 0;
  413. }
  414. deleteDemo();
  415. CommonExampleInterface::CreateFunc* func = gAllExamples->getExampleCreateFunc(demoIndex);
  416. if (func)
  417. {
  418. if (s_parameterInterface)
  419. {
  420. s_parameterInterface->removeAllParameters();
  421. }
  422. int option = gAllExamples->getExampleOption(demoIndex);
  423. s_guiHelper = new OpenGLGuiHelper(s_app, sUseOpenGL2);
  424. s_guiHelper->setVisualizerFlagCallback(OpenGLExampleBrowserVisualizerFlagCallback);
  425. CommonExampleOptions options(s_guiHelper, option);
  426. options.m_sharedMem = sSharedMem;
  427. sCurrentDemo = (*func)(options);
  428. if (sCurrentDemo)
  429. {
  430. if (gui2)
  431. {
  432. gui2->setStatusBarMessage("Status: OK", false);
  433. }
  434. b3Printf("Selected demo: %s", gAllExamples->getExampleName(demoIndex));
  435. if (gui2)
  436. {
  437. gui2->setExampleDescription(gAllExamples->getExampleDescription(demoIndex));
  438. }
  439. sCurrentDemo->initPhysics();
  440. if (resetCamera)
  441. {
  442. sCurrentDemo->resetCamera();
  443. }
  444. }
  445. }
  446. }
  447. #include <stdio.h>
  448. static void saveCurrentSettings(int currentEntry, const char* startFileName)
  449. {
  450. FILE* f = fopen(startFileName, "w");
  451. if (f)
  452. {
  453. fprintf(f, "--start_demo_name=%s\n", gAllExamples->getExampleName(sCurrentDemoIndex));
  454. fprintf(f, "--mouse_move_multiplier=%f\n", s_app->getMouseMoveMultiplier());
  455. fprintf(f, "--mouse_wheel_multiplier=%f\n", s_app->getMouseWheelMultiplier());
  456. float red, green, blue;
  457. s_app->getBackgroundColor(&red, &green, &blue);
  458. fprintf(f, "--background_color_red= %f\n", red);
  459. fprintf(f, "--background_color_green= %f\n", green);
  460. fprintf(f, "--background_color_blue= %f\n", blue);
  461. fprintf(f, "--fixed_timestep= %f\n", gFixedTimeStep);
  462. if (!gAllowRetina)
  463. {
  464. fprintf(f, "--disable_retina");
  465. }
  466. if (enable_experimental_opencl)
  467. {
  468. fprintf(f, "--enable_experimental_opencl\n");
  469. }
  470. // if (sUseOpenGL2 )
  471. // {
  472. // fprintf(f,"--opengl2\n");
  473. // }
  474. fclose(f);
  475. }
  476. };
  477. static void loadCurrentSettings(const char* startFileName, b3CommandLineArgs& args)
  478. {
  479. //int currentEntry= 0;
  480. FILE* f = fopen(startFileName, "r");
  481. if (f)
  482. {
  483. char oneline[1024];
  484. char* argv[] = {0, &oneline[0]};
  485. while (fgets(oneline, 1024, f) != NULL)
  486. {
  487. char* pos;
  488. if ((pos = strchr(oneline, '\n')) != NULL)
  489. *pos = '\0';
  490. args.addArgs(2, argv);
  491. }
  492. fclose(f);
  493. }
  494. };
  495. void MyComboBoxCallback(int comboId, const char* item)
  496. {
  497. //printf("comboId = %d, item = %s\n",comboId, item);
  498. if (comboId == DEMO_SELECTION_COMBOBOX)
  499. {
  500. //find selected item
  501. for (int i = 0; i < allNames.size(); i++)
  502. {
  503. if (strcmp(item, allNames[i]) == 0)
  504. {
  505. selectDemo(i);
  506. saveCurrentSettings(sCurrentDemoIndex, startFileName);
  507. break;
  508. }
  509. }
  510. }
  511. }
  512. //in case of multi-threading, don't submit messages while the GUI is rendering (causing crashes)
  513. static bool gBlockGuiMessages = false;
  514. void MyGuiPrintf(const char* msg)
  515. {
  516. printf("b3Printf: %s\n", msg);
  517. if (!gDisableDemoSelection && !gBlockGuiMessages)
  518. {
  519. gui2->textOutput(msg);
  520. gui2->forceUpdateScrollBars();
  521. }
  522. }
  523. void MyStatusBarPrintf(const char* msg)
  524. {
  525. printf("b3Printf: %s\n", msg);
  526. if (!gDisableDemoSelection && !gBlockGuiMessages)
  527. {
  528. bool isLeft = true;
  529. gui2->setStatusBarMessage(msg, isLeft);
  530. }
  531. }
  532. void MyStatusBarError(const char* msg)
  533. {
  534. printf("Warning: %s\n", msg);
  535. if (!gDisableDemoSelection && !gBlockGuiMessages)
  536. {
  537. bool isLeft = false;
  538. gui2->setStatusBarMessage(msg, isLeft);
  539. gui2->textOutput(msg);
  540. gui2->forceUpdateScrollBars();
  541. }
  542. btAssert(0);
  543. }
  544. struct MyMenuItemHander : public Gwen::Event::Handler
  545. {
  546. int m_buttonId;
  547. MyMenuItemHander(int buttonId)
  548. : m_buttonId(buttonId)
  549. {
  550. }
  551. void onButtonA(Gwen::Controls::Base* pControl)
  552. {
  553. //const Gwen::String& name = pControl->GetName();
  554. Gwen::Controls::TreeNode* node = (Gwen::Controls::TreeNode*)pControl;
  555. // Gwen::Controls::Label* l = node->GetButton();
  556. Gwen::UnicodeString la = node->GetButton()->GetText(); // node->GetButton()->GetName();// GetText();
  557. Gwen::String laa = Gwen::Utility::UnicodeToString(la);
  558. // const char* ha = laa.c_str();
  559. //printf("selected %s\n", ha);
  560. //int dep = but->IsDepressed();
  561. //int tog = but->GetToggleState();
  562. // if (m_data->m_toggleButtonCallback)
  563. // (*m_data->m_toggleButtonCallback)(m_buttonId, tog);
  564. }
  565. void onButtonB(Gwen::Controls::Base* pControl)
  566. {
  567. Gwen::Controls::Label* label = (Gwen::Controls::Label*)pControl;
  568. Gwen::UnicodeString la = label->GetText(); // node->GetButton()->GetName();// GetText();
  569. Gwen::String laa = Gwen::Utility::UnicodeToString(la);
  570. //const char* ha = laa.c_str();
  571. if (!gDisableDemoSelection)
  572. {
  573. selectDemo(sCurrentHightlighted);
  574. saveCurrentSettings(sCurrentDemoIndex, startFileName);
  575. }
  576. }
  577. void onButtonC(Gwen::Controls::Base* pControl)
  578. {
  579. /*Gwen::Controls::Label* label = (Gwen::Controls::Label*) pControl;
  580. Gwen::UnicodeString la = label->GetText();// node->GetButton()->GetName();// GetText();
  581. Gwen::String laa = Gwen::Utility::UnicodeToString(la);
  582. const char* ha = laa.c_str();
  583. printf("onButtonC ! %s\n", ha);
  584. */
  585. }
  586. void onButtonD(Gwen::Controls::Base* pControl)
  587. {
  588. /* Gwen::Controls::Label* label = (Gwen::Controls::Label*) pControl;
  589. Gwen::UnicodeString la = label->GetText();// node->GetButton()->GetName();// GetText();
  590. Gwen::String laa = Gwen::Utility::UnicodeToString(la);
  591. const char* ha = laa.c_str();
  592. */
  593. // printf("onKeyReturn ! \n");
  594. if (!gDisableDemoSelection)
  595. {
  596. selectDemo(sCurrentHightlighted);
  597. saveCurrentSettings(sCurrentDemoIndex, startFileName);
  598. }
  599. }
  600. void onButtonE(Gwen::Controls::Base* pControl)
  601. {
  602. // printf("select %d\n",m_buttonId);
  603. sCurrentHightlighted = m_buttonId;
  604. gui2->setExampleDescription(gAllExamples->getExampleDescription(sCurrentHightlighted));
  605. }
  606. void onButtonF(Gwen::Controls::Base* pControl)
  607. {
  608. //printf("selection changed!\n");
  609. }
  610. void onButtonG(Gwen::Controls::Base* pControl)
  611. {
  612. //printf("onButtonG !\n");
  613. }
  614. };
  615. void quitCallback()
  616. {
  617. s_window->setRequestExit();
  618. }
  619. void fileOpenCallback()
  620. {
  621. char filename[1024];
  622. int len = s_window->fileOpenDialog(filename, 1024);
  623. if (len)
  624. {
  625. //todo(erwincoumans) check if it is actually URDF
  626. //printf("file open:%s\n", filename);
  627. openFileDemo(filename);
  628. }
  629. }
  630. #define MAX_GRAPH_WINDOWS 5
  631. struct QuickCanvas : public Common2dCanvasInterface
  632. {
  633. GL3TexLoader* m_myTexLoader;
  634. MyGraphWindow* m_gw[MAX_GRAPH_WINDOWS];
  635. GraphingTexture* m_gt[MAX_GRAPH_WINDOWS];
  636. int m_curNumGraphWindows;
  637. QuickCanvas(GL3TexLoader* myTexLoader)
  638. : m_myTexLoader(myTexLoader),
  639. m_curNumGraphWindows(0)
  640. {
  641. for (int i = 0; i < MAX_GRAPH_WINDOWS; i++)
  642. {
  643. m_gw[i] = 0;
  644. m_gt[i] = 0;
  645. }
  646. }
  647. virtual ~QuickCanvas() {}
  648. virtual int createCanvas(const char* canvasName, int width, int height, int xPos, int yPos)
  649. {
  650. if (m_curNumGraphWindows < MAX_GRAPH_WINDOWS)
  651. {
  652. //find a slot
  653. int slot = m_curNumGraphWindows;
  654. btAssert(slot < MAX_GRAPH_WINDOWS);
  655. if (slot >= MAX_GRAPH_WINDOWS)
  656. return 0; //don't crash
  657. m_curNumGraphWindows++;
  658. MyGraphInput input(gui2->getInternalData());
  659. input.m_width = width;
  660. input.m_height = height;
  661. input.m_xPos = xPos;
  662. input.m_yPos = yPos;
  663. input.m_name = canvasName;
  664. input.m_texName = canvasName;
  665. m_gt[slot] = new GraphingTexture;
  666. m_gt[slot]->create(width, height);
  667. int texId = m_gt[slot]->getTextureId();
  668. m_myTexLoader->m_hashMap.insert(canvasName, texId);
  669. m_gw[slot] = setupTextureWindow(input);
  670. return slot;
  671. }
  672. return -1;
  673. }
  674. virtual void destroyCanvas(int canvasId)
  675. {
  676. btAssert(canvasId >= 0);
  677. delete m_gt[canvasId];
  678. m_gt[canvasId] = 0;
  679. destroyTextureWindow(m_gw[canvasId]);
  680. m_gw[canvasId] = 0;
  681. m_curNumGraphWindows--;
  682. }
  683. virtual void setPixel(int canvasId, int x, int y, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
  684. {
  685. btAssert(canvasId >= 0);
  686. btAssert(canvasId < m_curNumGraphWindows);
  687. m_gt[canvasId]->setPixel(x, y, red, green, blue, alpha);
  688. }
  689. virtual void getPixel(int canvasId, int x, int y, unsigned char& red, unsigned char& green, unsigned char& blue, unsigned char& alpha)
  690. {
  691. btAssert(canvasId >= 0);
  692. btAssert(canvasId < m_curNumGraphWindows);
  693. m_gt[canvasId]->getPixel(x, y, red, green, blue, alpha);
  694. }
  695. virtual void refreshImageData(int canvasId)
  696. {
  697. m_gt[canvasId]->uploadImageData();
  698. }
  699. };
  700. OpenGLExampleBrowser::OpenGLExampleBrowser(class ExampleEntries* examples)
  701. {
  702. m_internalData = new OpenGLExampleBrowserInternalData;
  703. gAllExamples = examples;
  704. }
  705. OpenGLExampleBrowser::~OpenGLExampleBrowser()
  706. {
  707. deleteDemo();
  708. for (int i = 0; i < m_internalData->m_nodes.size(); i++)
  709. {
  710. delete m_internalData->m_nodes[i];
  711. }
  712. delete m_internalData->m_handler2;
  713. for (int i = 0; i < m_internalData->m_handlers.size(); i++)
  714. {
  715. delete m_internalData->m_handlers[i];
  716. }
  717. m_internalData->m_handlers.clear();
  718. m_internalData->m_nodes.clear();
  719. delete s_parameterInterface;
  720. s_parameterInterface = 0;
  721. delete s_app->m_2dCanvasInterface;
  722. s_app->m_2dCanvasInterface = 0;
  723. #ifndef BT_NO_PROFILE
  724. destroyProfileWindow(m_internalData->m_profWindow);
  725. #endif
  726. m_internalData->m_gui->exit();
  727. delete m_internalData->m_gui;
  728. delete m_internalData->m_gwenRenderer;
  729. delete m_internalData->m_myTexLoader;
  730. delete m_internalData->m_app;
  731. s_app = 0;
  732. delete m_internalData;
  733. gFileImporterByExtension.clear();
  734. gAllExamples = 0;
  735. }
  736. #include "EmptyExample.h"
  737. bool OpenGLExampleBrowser::init(int argc, char* argv[])
  738. {
  739. b3CommandLineArgs args(argc, argv);
  740. loadCurrentSettings(startFileName, args);
  741. if (args.CheckCmdLineFlag("nogui"))
  742. {
  743. renderGrid = false;
  744. renderGui = false;
  745. }
  746. if (args.CheckCmdLineFlag("tracing"))
  747. {
  748. b3ChromeUtilsStartTimings();
  749. }
  750. args.GetCmdLineArgument("fixed_timestep", gFixedTimeStep);
  751. args.GetCmdLineArgument("png_skip_frames", gPngSkipFrames);
  752. ///The OpenCL rigid body pipeline is experimental and
  753. ///most OpenCL drivers and OpenCL compilers have issues with our kernels.
  754. ///If you have a high-end desktop GPU such as AMD 7970 or better, or NVIDIA GTX 680 with up-to-date drivers
  755. ///you could give it a try
  756. ///Note that several old OpenCL physics examples still have to be ported over to this new Example Browser
  757. if (args.CheckCmdLineFlag("enable_experimental_opencl"))
  758. {
  759. enable_experimental_opencl = true;
  760. gAllExamples->initOpenCLExampleEntries();
  761. }
  762. if (args.CheckCmdLineFlag("disable_retina"))
  763. {
  764. gAllowRetina = false;
  765. }
  766. int width = 1024;
  767. int height = 768;
  768. if (args.CheckCmdLineFlag("width"))
  769. {
  770. args.GetCmdLineArgument("width", width);
  771. }
  772. if (args.CheckCmdLineFlag("height"))
  773. {
  774. args.GetCmdLineArgument("height", height);
  775. }
  776. #ifndef NO_OPENGL3
  777. SimpleOpenGL3App* simpleApp = 0;
  778. sUseOpenGL2 = args.CheckCmdLineFlag("opengl2");
  779. args.GetCmdLineArgument("render_device", gRenderDevice);
  780. args.GetCmdLineArgument("window_backend", gWindowBackend);
  781. #else
  782. sUseOpenGL2 = true;
  783. #endif
  784. const char* appTitle = "Bullet Physics ExampleBrowser";
  785. #if defined(_DEBUG) || defined(DEBUG)
  786. const char* optMode = "Debug build (slow)";
  787. #else
  788. const char* optMode = "Release build";
  789. #endif
  790. #ifdef B3_USE_GLFW
  791. const char* glContext = "[glfw]";
  792. #else
  793. const char* glContext = "[btgl]";
  794. #endif
  795. if (sUseOpenGL2)
  796. {
  797. char title[1024];
  798. sprintf(title, "%s using limited OpenGL2 fallback %s %s", appTitle, glContext, optMode);
  799. s_app = new SimpleOpenGL2App(title, width, height);
  800. s_app->m_renderer = new SimpleOpenGL2Renderer(width, height);
  801. }
  802. #ifndef NO_OPENGL3
  803. else
  804. {
  805. char title[1024];
  806. sprintf(title, "%s using OpenGL3+ %s %s", appTitle, glContext, optMode);
  807. simpleApp = new SimpleOpenGL3App(title, width, height, gAllowRetina, gWindowBackend, gRenderDevice);
  808. s_app = simpleApp;
  809. }
  810. #endif
  811. m_internalData->m_app = s_app;
  812. char* gVideoFileName = 0;
  813. args.GetCmdLineArgument("mp4", gVideoFileName);
  814. int gVideoFps = 0;
  815. args.GetCmdLineArgument("mp4fps", gVideoFps);
  816. if (gVideoFps)
  817. {
  818. simpleApp->setMp4Fps(gVideoFps);
  819. }
  820. #ifndef NO_OPENGL3
  821. if (gVideoFileName)
  822. simpleApp->dumpFramesToVideo(gVideoFileName);
  823. #endif
  824. s_instancingRenderer = s_app->m_renderer;
  825. s_window = s_app->m_window;
  826. width = s_window->getWidth();
  827. height = s_window->getHeight();
  828. prevMouseMoveCallback = s_window->getMouseMoveCallback();
  829. s_window->setMouseMoveCallback(MyMouseMoveCallback);
  830. prevMouseButtonCallback = s_window->getMouseButtonCallback();
  831. s_window->setMouseButtonCallback(MyMouseButtonCallback);
  832. prevKeyboardCallback = s_window->getKeyboardCallback();
  833. s_window->setKeyboardCallback(MyKeyboardCallback);
  834. s_app->m_renderer->getActiveCamera()->setCameraDistance(13);
  835. s_app->m_renderer->getActiveCamera()->setCameraPitch(0);
  836. s_app->m_renderer->getActiveCamera()->setCameraTargetPosition(0, 0, 0);
  837. float mouseMoveMult = s_app->getMouseMoveMultiplier();
  838. if (args.GetCmdLineArgument("mouse_move_multiplier", mouseMoveMult))
  839. {
  840. s_app->setMouseMoveMultiplier(mouseMoveMult);
  841. }
  842. float mouseWheelMult = s_app->getMouseWheelMultiplier();
  843. if (args.GetCmdLineArgument("mouse_wheel_multiplier", mouseWheelMult))
  844. {
  845. s_app->setMouseWheelMultiplier(mouseWheelMult);
  846. }
  847. args.GetCmdLineArgument("shared_memory_key", gSharedMemoryKey);
  848. float red, green, blue;
  849. s_app->getBackgroundColor(&red, &green, &blue);
  850. args.GetCmdLineArgument("background_color_red", red);
  851. args.GetCmdLineArgument("background_color_green", green);
  852. args.GetCmdLineArgument("background_color_blue", blue);
  853. s_app->setBackgroundColor(red, green, blue);
  854. b3SetCustomWarningMessageFunc(MyGuiPrintf);
  855. b3SetCustomPrintfFunc(MyGuiPrintf);
  856. b3SetCustomErrorMessageFunc(MyStatusBarError);
  857. assert(glGetError() == GL_NO_ERROR);
  858. {
  859. GL3TexLoader* myTexLoader = new GL3TexLoader;
  860. m_internalData->m_myTexLoader = myTexLoader;
  861. if (sUseOpenGL2)
  862. {
  863. m_internalData->m_gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(s_window->getRetinaScale());
  864. }
  865. #ifndef NO_OPENGL3
  866. else
  867. {
  868. sth_stash* fontstash = simpleApp->getFontStash();
  869. m_internalData->m_gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer, fontstash, width, height, s_window->getRetinaScale(), myTexLoader);
  870. }
  871. #endif
  872. gui2 = new GwenUserInterface;
  873. m_internalData->m_gui = gui2;
  874. m_internalData->m_myTexLoader = myTexLoader;
  875. gui2->init(width, height, m_internalData->m_gwenRenderer, s_window->getRetinaScale());
  876. }
  877. //gui = 0;// new GwenUserInterface;
  878. GL3TexLoader* myTexLoader = m_internalData->m_myTexLoader;
  879. // = myTexLoader;
  880. //
  881. if (gui2)
  882. {
  883. // gui->getInternalData()->m_explorerPage
  884. Gwen::Controls::TreeControl* tree = gui2->getInternalData()->m_explorerTreeCtrl;
  885. //gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader);
  886. #ifndef BT_NO_PROFILE
  887. s_profWindow = setupProfileWindow(gui2->getInternalData());
  888. m_internalData->m_profWindow = s_profWindow;
  889. profileWindowSetVisible(s_profWindow, false);
  890. #endif //BT_NO_PROFILE
  891. gui2->setFocus();
  892. s_parameterInterface = s_app->m_parameterInterface = new GwenParameterInterface(gui2->getInternalData());
  893. s_app->m_2dCanvasInterface = new QuickCanvas(myTexLoader);
  894. ///add some demos to the gAllExamples
  895. int numDemos = gAllExamples->getNumRegisteredExamples();
  896. //char nodeText[1024];
  897. //int curDemo = 0;
  898. int selectedDemo = 0;
  899. Gwen::Controls::TreeNode* curNode = tree;
  900. m_internalData->m_handler2 = new MyMenuItemHander(-1);
  901. char* demoNameFromCommandOption = 0;
  902. args.GetCmdLineArgument("start_demo_name", demoNameFromCommandOption);
  903. if (demoNameFromCommandOption)
  904. {
  905. selectedDemo = -1;
  906. }
  907. tree->onReturnKeyDown.Add(m_internalData->m_handler2, &MyMenuItemHander::onButtonD);
  908. int firstAvailableDemoIndex = -1;
  909. Gwen::Controls::TreeNode* firstNode = 0;
  910. for (int d = 0; d < numDemos; d++)
  911. {
  912. // sprintf(nodeText, "Node %d", i);
  913. Gwen::UnicodeString nodeUText = Gwen::Utility::StringToUnicode(gAllExamples->getExampleName(d));
  914. if (gAllExamples->getExampleCreateFunc(d)) //was test for gAllExamples[d].m_menuLevel==1
  915. {
  916. Gwen::Controls::TreeNode* pNode = curNode->AddNode(nodeUText);
  917. if (firstAvailableDemoIndex < 0)
  918. {
  919. firstAvailableDemoIndex = d;
  920. firstNode = pNode;
  921. }
  922. if (d == selectedDemo)
  923. {
  924. firstAvailableDemoIndex = d;
  925. firstNode = pNode;
  926. //pNode->SetSelected(true);
  927. //tree->ExpandAll();
  928. // tree->ForceUpdateScrollBars();
  929. //tree->OnKeyLeft(true);
  930. // tree->OnKeyRight(true);
  931. //tree->ExpandAll();
  932. // selectDemo(d);
  933. }
  934. if (demoNameFromCommandOption)
  935. {
  936. const char* demoName = gAllExamples->getExampleName(d);
  937. int res = strcmp(demoName, demoNameFromCommandOption);
  938. if (res == 0)
  939. {
  940. firstAvailableDemoIndex = d;
  941. firstNode = pNode;
  942. }
  943. }
  944. #if 1
  945. MyMenuItemHander* handler = new MyMenuItemHander(d);
  946. m_internalData->m_handlers.push_back(handler);
  947. pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA);
  948. pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB);
  949. pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC);
  950. pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE);
  951. pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG);
  952. pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF);
  953. #endif
  954. // pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD);
  955. // pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD);
  956. // pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD);
  957. // pNode->onKeyboardPressed.Add(handler, &MyMenuItemHander::onButtonD);
  958. // pNode->OnKeyPress
  959. }
  960. else
  961. {
  962. curNode = tree->AddNode(nodeUText);
  963. m_internalData->m_nodes.push_back(curNode);
  964. }
  965. }
  966. if (sCurrentDemo == 0)
  967. {
  968. if (firstAvailableDemoIndex >= 0)
  969. {
  970. firstNode->SetSelected(true);
  971. while (firstNode != tree)
  972. {
  973. firstNode->ExpandAll();
  974. firstNode = (Gwen::Controls::TreeNode*)firstNode->GetParent();
  975. }
  976. selectDemo(firstAvailableDemoIndex);
  977. }
  978. }
  979. free(demoNameFromCommandOption);
  980. demoNameFromCommandOption = 0;
  981. btAssert(sCurrentDemo != 0);
  982. if (sCurrentDemo == 0)
  983. {
  984. printf("Error, no demo/example\n");
  985. exit(0);
  986. }
  987. gui2->registerFileOpenCallback(fileOpenCallback);
  988. gui2->registerQuitCallback(quitCallback);
  989. }
  990. return true;
  991. }
  992. CommonExampleInterface* OpenGLExampleBrowser::getCurrentExample()
  993. {
  994. btAssert(sCurrentDemo);
  995. return sCurrentDemo;
  996. }
  997. bool OpenGLExampleBrowser::requestedExit()
  998. {
  999. return s_window->requestedExit();
  1000. }
  1001. void OpenGLExampleBrowser::updateGraphics()
  1002. {
  1003. if (sCurrentDemo)
  1004. {
  1005. if (!pauseSimulation || singleStepSimulation)
  1006. {
  1007. //B3_PROFILE("sCurrentDemo->updateGraphics");
  1008. sCurrentDemo->updateGraphics();
  1009. }
  1010. }
  1011. }
  1012. void OpenGLExampleBrowser::update(float deltaTime)
  1013. {
  1014. b3ChromeUtilsEnableProfiling();
  1015. if (!gEnableRenderLoop && !singleStepSimulation)
  1016. {
  1017. B3_PROFILE("updateGraphics");
  1018. sCurrentDemo->updateGraphics();
  1019. return;
  1020. }
  1021. B3_PROFILE("OpenGLExampleBrowser::update");
  1022. //assert(glGetError() == GL_NO_ERROR);
  1023. {
  1024. B3_PROFILE("s_instancingRenderer");
  1025. s_instancingRenderer->init();
  1026. }
  1027. DrawGridData dg;
  1028. dg.upAxis = s_app->getUpAxis();
  1029. {
  1030. BT_PROFILE("Update Camera and Light");
  1031. s_instancingRenderer->updateCamera(dg.upAxis);
  1032. }
  1033. static int frameCount = 0;
  1034. frameCount++;
  1035. if (0)
  1036. {
  1037. BT_PROFILE("Draw frame counter");
  1038. char bla[1024];
  1039. sprintf(bla, "Frame %d", frameCount);
  1040. s_app->drawText(bla, 10, 10);
  1041. }
  1042. if (gPngFileName)
  1043. {
  1044. static int skip = 0;
  1045. skip--;
  1046. if (skip < 0)
  1047. {
  1048. skip = gPngSkipFrames;
  1049. //printf("gPngFileName=%s\n",gPngFileName);
  1050. static int s_frameCount = 0;
  1051. sprintf(staticPngFileName, "%s%d.png", gPngFileName, s_frameCount++);
  1052. //b3Printf("Made screenshot %s",staticPngFileName);
  1053. s_app->dumpNextFrameToPng(staticPngFileName);
  1054. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1055. }
  1056. }
  1057. if (sCurrentDemo)
  1058. {
  1059. if (!pauseSimulation || singleStepSimulation)
  1060. {
  1061. //printf("---------------------------------------------------\n");
  1062. //printf("Framecount = %d\n",frameCount);
  1063. B3_PROFILE("sCurrentDemo->stepSimulation");
  1064. if (gFixedTimeStep > 0)
  1065. {
  1066. sCurrentDemo->stepSimulation(gFixedTimeStep);
  1067. }
  1068. else
  1069. {
  1070. sCurrentDemo->stepSimulation(deltaTime); //1./60.f);
  1071. }
  1072. }
  1073. if (renderGrid)
  1074. {
  1075. BT_PROFILE("Draw Grid");
  1076. //glPolygonOffset(3.0, 3);
  1077. //glEnable(GL_POLYGON_OFFSET_FILL);
  1078. s_app->drawGrid(dg);
  1079. }
  1080. if (renderVisualGeometry && ((gDebugDrawFlags & btIDebugDraw::DBG_DrawWireframe) == 0))
  1081. {
  1082. if (visualWireframe)
  1083. {
  1084. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  1085. }
  1086. BT_PROFILE("Render Scene");
  1087. sCurrentDemo->renderScene();
  1088. }
  1089. else
  1090. {
  1091. B3_PROFILE("physicsDebugDraw");
  1092. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  1093. sCurrentDemo->physicsDebugDraw(gDebugDrawFlags);
  1094. }
  1095. }
  1096. {
  1097. if (gui2 && s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera())
  1098. {
  1099. B3_PROFILE("setStatusBarMessage");
  1100. char msg[1024];
  1101. float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance();
  1102. float pitch = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraPitch();
  1103. float yaw = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraYaw();
  1104. float camTarget[3];
  1105. float camPos[3];
  1106. s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraPosition(camPos);
  1107. s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraTargetPosition(camTarget);
  1108. sprintf(msg, "camTargetPos=%2.2f,%2.2f,%2.2f, dist=%2.2f, pitch=%2.2f, yaw=%2.2f", camTarget[0], camTarget[1], camTarget[2], camDist, pitch, yaw);
  1109. gui2->setStatusBarMessage(msg, true);
  1110. }
  1111. }
  1112. static int toggle = 1;
  1113. if (renderGui)
  1114. {
  1115. B3_PROFILE("renderGui");
  1116. #ifndef BT_NO_PROFILE
  1117. if (!pauseSimulation || singleStepSimulation)
  1118. {
  1119. if (isProfileWindowVisible(s_profWindow))
  1120. {
  1121. processProfileData(s_profWindow, false);
  1122. }
  1123. }
  1124. #endif //#ifndef BT_NO_PROFILE
  1125. {
  1126. B3_PROFILE("updateOpenGL");
  1127. if (sUseOpenGL2)
  1128. {
  1129. saveOpenGLState(s_instancingRenderer->getScreenWidth() * s_window->getRetinaScale(), s_instancingRenderer->getScreenHeight() * s_window->getRetinaScale());
  1130. }
  1131. if (m_internalData->m_gui)
  1132. {
  1133. gBlockGuiMessages = true;
  1134. m_internalData->m_gui->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight());
  1135. gBlockGuiMessages = false;
  1136. }
  1137. if (sUseOpenGL2)
  1138. {
  1139. restoreOpenGLState();
  1140. }
  1141. }
  1142. }
  1143. singleStepSimulation = false;
  1144. toggle = 1 - toggle;
  1145. {
  1146. BT_PROFILE("Sync Parameters");
  1147. if (s_parameterInterface)
  1148. {
  1149. s_parameterInterface->syncParameters();
  1150. }
  1151. }
  1152. {
  1153. BT_PROFILE("Swap Buffers");
  1154. s_app->swapBuffer();
  1155. }
  1156. if (gui2)
  1157. {
  1158. B3_PROFILE("forceUpdateScrollBars");
  1159. gui2->forceUpdateScrollBars();
  1160. }
  1161. }
  1162. void OpenGLExampleBrowser::setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
  1163. {
  1164. gDisableDemoSelection = true;
  1165. sSharedMem = sharedMem;
  1166. }