int main(int argc, char* argv[]) { int sz = sizeof(b3Generic6DofConstraint); int sz2 = sizeof(b3Point2PointConstraint); int sz3 = sizeof(b3TypedConstraint); int sz4 = sizeof(b3TranslationalLimitMotor); int sz5 = sizeof(b3RotationalLimitMotor); int sz6 = sizeof(b3Transform); //b3OpenCLUtils::setCachePath("/Users/erwincoumans/develop/mycache"); b3SetCustomEnterProfileZoneFunc(b3ProfileManager::Start_Profile); b3SetCustomLeaveProfileZoneFunc(b3ProfileManager::Stop_Profile); b3SetCustomPrintfFunc(myprintf); b3Vector3 test=b3MakeVector3(1,2,3); test.x = 1; test.y = 4; printf("main start"); b3CommandLineArgs args(argc,argv); ParticleDemo::ConstructionInfo ci; if (args.CheckCmdLineFlag("help")) { Usage(); return 0; } selectedDemo = loadCurrentDemoEntry(sStartFileName); args.GetCmdLineArgument("selected_demo",selectedDemo); if (args.CheckCmdLineFlag("new_batching")) { useNewBatchingKernel = true; } bool benchmark=args.CheckCmdLineFlag("benchmark"); args.GetCmdLineArgument("max_framecount",maxFrameCount); args.GetCmdLineArgument("shadowmap_size",shadowMapWorldSize); args.GetCmdLineArgument("shadowmap_resolution",shadowMapWidth); shadowMapHeight=shadowMapWidth; if (args.CheckCmdLineFlag("disable_shadowmap")) { useShadowMap = false; } args.GetCmdLineArgument("pair_benchmark_file",gPairBenchFileName); gDebugLauncherCL = args.CheckCmdLineFlag("debug_kernel_launch"); dump_timings=args.CheckCmdLineFlag("dump_timings"); ci.useOpenCL = !args.CheckCmdLineFlag("disable_opencl"); ci.m_useConcaveMesh = true;//args.CheckCmdLineFlag("use_concave_mesh"); if (ci.m_useConcaveMesh) { enableExperimentalCpuConcaveCollision = true; } ci.m_useInstancedCollisionShapes = !args.CheckCmdLineFlag("no_instanced_collision_shapes"); args.GetCmdLineArgument("cl_device", ci.preferredOpenCLDeviceIndex); args.GetCmdLineArgument("cl_platform", ci.preferredOpenCLPlatformIndex); gAllowCpuOpenCL = args.CheckCmdLineFlag("allow_opencl_cpu"); gUseLargeBatches = args.CheckCmdLineFlag("use_large_batches"); gUseJacobi = args.CheckCmdLineFlag("use_jacobi"); gUseDbvt = args.CheckCmdLineFlag("use_dbvt"); gDumpContactStats = args.CheckCmdLineFlag("dump_contact_stats"); gCalcWorldSpaceAabbOnCpu = args.CheckCmdLineFlag("calc_aabb_cpu"); gUseCalculateOverlappingPairsHost = args.CheckCmdLineFlag("calc_pairs_cpu"); gIntegrateOnCpu = args.CheckCmdLineFlag("integrate_cpu"); gConvertConstraintOnCpu = args.CheckCmdLineFlag("convert_constraints_cpu"); useUniformGrid = args.CheckCmdLineFlag("use_uniform_grid"); args.GetCmdLineArgument("x_dim", ci.arraySizeX); args.GetCmdLineArgument("y_dim", ci.arraySizeY); args.GetCmdLineArgument("z_dim", ci.arraySizeZ); args.GetCmdLineArgument("x_gap", ci.gapX); args.GetCmdLineArgument("y_gap", ci.gapY); args.GetCmdLineArgument("z_gap", ci.gapZ); gPause = args.CheckCmdLineFlag("paused"); gDebugForceLoadingFromSource = args.CheckCmdLineFlag("load_cl_kernels_from_disk"); gDebugSkipLoadingBinary = args.CheckCmdLineFlag("disable_cached_cl_kernels"); #ifndef B3_NO_PROFILE b3ProfileManager::Reset(); #endif //B3_NO_PROFILE window = new b3gDefaultOpenGLWindow(); b3gWindowConstructionInfo wci(g_OpenGLWidth,g_OpenGLHeight); window->createWindow(wci); window->setResizeCallback(MyResizeCallback); window->setMouseMoveCallback(MyMouseMoveCallback); window->setMouseButtonCallback(MyMouseButtonCallback); window->setKeyboardCallback(MyKeyboardCallback); window->setWindowTitle("Bullet 3.x GPU Rigid Body http://bulletphysics.org"); printf("-----------------------------------------------------\n"); #ifndef __APPLE__ glewInit(); #endif gui = new GwenUserInterface(); printf("started GwenUserInterface"); GLPrimitiveRenderer prim(g_OpenGLWidth,g_OpenGLHeight); stash = initFont(&prim); if (gui) { gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale()); printf("init fonts"); gui->setToggleButtonCallback(MyButtonCallback); gui->registerToggleButton(MYPAUSE,"Pause"); gui->registerToggleButton(MYPROFILE,"Profile"); gui->registerToggleButton(MYRESET,"Reset"); int numItems = sizeof(allDemos)/sizeof(ParticleDemo::CreateFunc*); demoNames.clear(); for (int i=0;i<numItems;i++) { GpuDemo* demo = allDemos[i](); demoNames.push_back(demo->getName()); delete demo; } gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0],selectedDemo); gui->setComboBoxCallback(MyComboBoxCallback); } do { bool syncOnly = false; gReset = false; { GLint err; glEnable(GL_BLEND); err = glGetError(); b3Assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); err = glGetError(); b3Assert(err==GL_NO_ERROR); window->startRendering(); glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH_TEST); sth_begin_draw(stash); //sth_draw_text(stash, droidRegular,12.f, dx, dy-50, "How does this OpenGL True Type font look? ", &dx,width,height); int spacing = 0;//g_OpenGLHeight; float sx,sy,dx,dy,lh; sx = 0; sy = g_OpenGLHeight; dx = sx; dy = sy; //if (1) const char* msg[] = {"Please wait, initializing the OpenCL demo", "Please make sure to run the demo on a high-end discrete GPU with OpenCL support", "The first time it can take a bit longer to compile the OpenCL kernels.", "Check the console if it takes longer than 1 minute or if a demos has issues.", "Please share the full commandline output when reporting issues:", "App_Bullet3_OpenCL_Demos_* >> error.log", "", "", #ifdef _DEBUG "Some of the demos load a large .obj file,", "please use an optimized build of this app for faster parsing", "", "", #endif "You can press F1 to create a single screenshot,", "or press F2 toggle screenshot (useful to create movies)", "", "", "There are various command-line options such as --benchmark", "See http://github.com/erwincoumans/bullet3 for more information" }; int fontSize = 68; int nummsg = sizeof(msg)/sizeof(const char*); for (int i=0;i<nummsg;i++) { char txt[512]; sprintf(txt,"%s",msg[i]); //sth_draw_text(stash, droidRegular,i, 10, dy-spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight); sth_draw_text(stash, droidRegular,fontSize, 10, spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight); spacing+=fontSize; fontSize = 32; } sth_end_draw(stash); sth_flush_draw(stash); window->endRendering(); } static bool once=true; //glClearColor(0.3f, 0.3f, 0.3f, 1.0f); glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); window->setWheelCallback(b3DefaultWheelCallback); { GpuDemo* demo = allDemos[selectedDemo](); sDemo = demo; // demo->myinit(); bool useGpu = false; //int maxObjectCapacity=128*1024; int maxObjectCapacity=1024*1024; maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10); { ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer(); ci.m_window = window; ci.m_gui = gui; ci.m_instancingRenderer->init(); ci.m_instancingRenderer->resize(g_OpenGLWidth,g_OpenGLHeight); ci.m_instancingRenderer->InitShaders(); ci.m_primRenderer = &prim; // render.init(); } { demo->initPhysics(ci); } printf("-----------------------------------------------------\n"); FILE* csvFile = 0; FILE* detailsFile = 0; if (benchmark) { char prefixFileName[1024]; char csvFileName[1024]; char detailsFileName[1024]; b3OpenCLDeviceInfo info; b3OpenCLUtils::getDeviceInfo(demo->getInternalData()->m_clDevice,&info); //todo: move this time stuff into the Platform/Window class #ifdef _WIN32 SYSTEMTIME time; GetLocalTime(&time); char buf[1024]; DWORD dwCompNameLen = 1024; if (0 != GetComputerName(buf, &dwCompNameLen)) { printf("%s", buf); } else { printf("unknown", buf); } sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,time.wDay,time.wMonth,time.wYear,time.wHour,time.wMinute,time.wSecond); #else timeval now; gettimeofday(&now,0); struct tm* ptm; ptm = localtime (&now.tv_sec); char buf[1024]; #ifdef __APPLE__ sprintf(buf,"MacOSX"); #else sprintf(buf,"Unix"); #endif sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ, ptm->tm_mday, ptm->tm_mon+1, ptm->tm_year+1900, ptm->tm_hour, ptm->tm_min, ptm->tm_sec); #endif sprintf(csvFileName,"%s.csv",prefixFileName); sprintf(detailsFileName,"%s.txt",prefixFileName); printf("Open csv file %s and details file %s\n", csvFileName,detailsFileName); //GetSystemTime(&time2); csvFile=fopen(csvFileName,"w"); detailsFile = fopen(detailsFileName,"w"); if (detailsFile) defaultOutput = detailsFile; //if (f) // fprintf(f,"%s (%dx%dx%d=%d),\n", g_deviceName,ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ); } fprintf(defaultOutput,"Demo settings:\n"); fprintf(defaultOutput," SelectedDemo=%d, demoname = %s\n", selectedDemo, demo->getName()); fprintf(defaultOutput," x_dim=%d, y_dim=%d, z_dim=%d\n",ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ); fprintf(defaultOutput," x_gap=%f, y_gap=%f, z_gap=%f\n",ci.gapX,ci.gapY,ci.gapZ); fprintf(defaultOutput,"\nOpenCL settings:\n"); fprintf(defaultOutput," Preferred cl_device index %d\n", ci.preferredOpenCLDeviceIndex); fprintf(defaultOutput," Preferred cl_platform index%d\n", ci.preferredOpenCLPlatformIndex); fprintf(defaultOutput,"\n"); if (demo->getInternalData()->m_platformId) { b3OpenCLUtils::printPlatformInfo( demo->getInternalData()->m_platformId); fprintf(defaultOutput,"\n"); b3OpenCLUtils::printDeviceInfo( demo->getInternalData()->m_clDevice); fprintf(defaultOutput,"\n"); } do { GLint err = glGetError(); assert(err==GL_NO_ERROR); if (exportFrame || exportMovie) { if (!renderTexture) { renderTexture = new GLRenderToTexture(); GLuint renderTextureId; glGenTextures(1, &renderTextureId); // "Bind" the newly created texture : all future texture functions will modify this texture glBindTexture(GL_TEXTURE_2D, renderTextureId); // Give an empty image to OpenGL ( the last "0" ) //glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0); //glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); renderTexture->init(g_OpenGLWidth,g_OpenGLHeight,renderTextureId, RENDERTEXTURE_COLOR); } bool result = renderTexture->enable(); } err = glGetError(); assert(err==GL_NO_ERROR); b3ProfileManager::Reset(); b3ProfileManager::Increment_Frame_Counter(); // render.reshape(g_OpenGLWidth,g_OpenGLHeight); ci.m_instancingRenderer->resize(g_OpenGLWidth,g_OpenGLHeight); prim.setScreenSize(g_OpenGLWidth,g_OpenGLHeight); err = glGetError(); assert(err==GL_NO_ERROR); window->startRendering(); err = glGetError(); assert(err==GL_NO_ERROR); glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); if (!gPause) { B3_PROFILE("clientMoveAndDisplay"); demo->clientMoveAndDisplay(); } else { } { B3_PROFILE("renderScene"); demo->renderScene(); } err = glGetError(); assert(err==GL_NO_ERROR); /*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects()) { B3_PROFILE("renderPhysicsWorld"); b3AlignedObjectArray<b3CollisionObject*> arr = demo->getDynamicsWorld()->getCollisionObjectArray(); b3CollisionObject** colObjArray = &arr[0]; render.renderPhysicsWorld(demo->getDynamicsWorld()->getNumCollisionObjects(),colObjArray, syncOnly); syncOnly = true; } */ if (exportFrame || exportMovie) { char fileName[1024]; sprintf(fileName,"screenShot%d.png",frameIndex++); writeTextureToPng(g_OpenGLWidth,g_OpenGLHeight,fileName); exportFrame = false; renderTexture->disable(); } { B3_PROFILE("gui->draw"); if (gui && gDrawGui) gui->draw(g_OpenGLWidth,g_OpenGLHeight); } err = glGetError(); assert(err==GL_NO_ERROR); { B3_PROFILE("window->endRendering"); window->endRendering(); } err = glGetError(); assert(err==GL_NO_ERROR); { B3_PROFILE("glFinish"); } if (dump_timings) { b3ProfileManager::dumpAll(stdout); } if (csvFile) { static int frameCount=0; if (frameCount>0) { DumpSimulationTime(csvFile); if (detailsFile) { fprintf(detailsFile,"\n==================================\nFrame %d:\n", frameCount); b3ProfileManager::dumpAll(detailsFile); } } if (frameCount>=maxFrameCount) window->setRequestExit(); frameCount++; } if (gStep) gPause=true; } while (!window->requestedExit() && !gReset); demo->exitPhysics(); b3ProfileManager::CleanupMemory(); delete ci.m_instancingRenderer; delete demo; sDemo = 0; if (detailsFile) { fclose(detailsFile); detailsFile=0; } if (csvFile) { fclose(csvFile); csvFile=0; } } } while (gReset); if (gui) gui->setComboBoxCallback(0); { delete gui; gui=0; exitFont(); window->closeWindow(); delete window; window = 0; } return 0; }
int main(int argc, char* argv[]) { sOpenGLVerbose = false; float dt = 1./120.f; int width = 1024; int height=768; 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); app->m_window->setKeyboardCallback(MyKeyboardCallback); GLint err = glGetError(); assert(err==GL_NO_ERROR); sth_stash* fontstash=app->getFontStash(); gui = new GwenUserInterface; gui->init(width,height,fontstash,app->m_window->getRetinaScale()); int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry); for (int i=0;i<numDemos;i++) { allNames.push_back(allDemos[i].m_name); } selectDemo(loadCurrentDemoEntry(startFileName)); gui->registerComboBox(DEMO_SELECTION_COMBOBOX,allNames.size(),&allNames[0],sCurrentDemoIndex); //const char* names2[] = {"comboF", "comboG","comboH"}; //gui->registerComboBox(2,3,&names2[0],0); gui->setComboBoxCallback(MyComboBoxCallback); do { GLint err = glGetError(); assert(err==GL_NO_ERROR); app->m_instancingRenderer->init(); app->m_instancingRenderer->updateCamera(); app->drawGrid(); if (0) { char bla[1024]; static int frameCount = 0; frameCount++; sprintf(bla,"Simple test frame %d", frameCount); app->drawText(bla,10,10); } if (sCurrentDemo) { if (!pauseSimulation) sCurrentDemo->stepSimulation(1./60.f); sCurrentDemo->renderScene(); } 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()); selectDemo(0); delete gui; delete app; return 0; }
int main(int argc, char* argv[]) { shadowMapWorldSize = 25; b3Clock clock; float dt = 1./120.f; int width = 1024; int height=768; 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); app->m_window->setKeyboardCallback(MyKeyboardCallback); GLint err = glGetError(); assert(err==GL_NO_ERROR); sth_stash* fontstash=app->getFontStash(); gui = new GwenUserInterface; gui->init(width,height,fontstash,app->m_window->getRetinaScale()); // gui->getInternalData()->m_explorerPage Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl; app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData()); //gui->getInternalData()->m_demoPage; int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry); char nodeText[1024]; int curDemo = 0; int selectedDemo = loadCurrentDemoEntry(startFileName); Gwen::Controls::TreeNode* curNode = tree; MyMenuItemHander* handler2 = new MyMenuItemHander(-1); tree->onReturnKeyDown.Add(handler2, &MyMenuItemHander::onButtonD); for (int d = 0; d<numDemos; d++) { // sprintf(nodeText, "Node %d", i); Gwen::UnicodeString nodeUText = Gwen::Utility::StringToUnicode(allDemos[d].m_name); if (allDemos[d].m_menuLevel==1) { Gwen::Controls::TreeNode* pNode = curNode->AddNode(nodeUText); if (d == selectedDemo) { pNode->SetSelected(true); tree->ExpandAll(); selectDemo(d); } MyMenuItemHander* handler = new MyMenuItemHander(d); pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA); pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB); pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC); pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE); pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG); pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF); // pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onKeyboardPressed.Add(handler, &MyMenuItemHander::onButtonD); // pNode->OnKeyPress } else { curNode = tree->AddNode(nodeUText); } } /* for (int i=0;i<numDemos;i++) { allNames.push_back(allDemos[i].m_name); } */ //selectDemo(loadCurrentDemoEntry(startFileName)); /* gui->registerComboBox(DEMO_SELECTION_COMBOBOX,allNames.size(),&allNames[0],sCurrentDemoIndex); //const char* names2[] = {"comboF", "comboG","comboH"}; //gui->registerComboBox(2,3,&names2[0],0); gui->setComboBoxCallback(MyComboBoxCallback); */ unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds(); do { GLint err = glGetError(); assert(err==GL_NO_ERROR); app->m_instancingRenderer->init(); DrawGridData dg; dg.upAxis = app->getUpAxis(); app->m_instancingRenderer->updateCamera(dg.upAxis); app->drawGrid(dg); static int frameCount = 0; frameCount++; if (0) { char bla[1024]; sprintf(bla,"Simple test frame %d", frameCount); app->drawText(bla,10,10); } if (sCurrentDemo) { if (!pauseSimulation) { unsigned long int curTimeInMicroseconds = clock.getTimeMicroseconds(); unsigned long int diff = curTimeInMicroseconds-prevTimeInMicroseconds; float deltaTimeInSeconds = (diff)*1.e-6; //printf("---------------------------------------------------\n"); //printf("Framecount = %d\n",frameCount); sCurrentDemo->stepSimulation(deltaTimeInSeconds);//1./60.f); prevTimeInMicroseconds = curTimeInMicroseconds; } sCurrentDemo->renderScene(); sCurrentDemo->physicsDebugDraw(); } static int toggle = 1; if (1) { gui->draw(app->m_instancingRenderer->getScreenWidth(),app->m_instancingRenderer->getScreenHeight()); } toggle=1-toggle; app->m_parameterInterface->syncParameters(); app->swapBuffer(); } while (!app->m_window->requestedExit()); // selectDemo(0); delete gui; delete app; return 0; }
int main(int argc, char* argv[]) { shadowMapWorldSize = 25; b3Clock clock; //float dt = 1./120.f; int width = 1024; int height=768; // wci.m_resizeCallback = MyResizeCallback; SimpleOpenGL3App* simpleApp=0; bool useOpenGL2=false; if (useOpenGL2) { app = new SimpleOpenGL2App("AllBullet2Demos",width,height); app->m_renderer = new SimpleOpenGL2Renderer(width,height); } else { simpleApp = new SimpleOpenGL3App("AllBullet2Demos",width,height); app = simpleApp; } s_instancingRenderer = app->m_renderer; s_window = app->m_window; prevMouseMoveCallback = s_window->getMouseMoveCallback(); s_window->setMouseMoveCallback(MyMouseMoveCallback); prevMouseButtonCallback = s_window->getMouseButtonCallback(); s_window->setMouseButtonCallback(MyMouseButtonCallback); prevKeyboardCallback = s_window->getKeyboardCallback(); s_window->setKeyboardCallback(MyKeyboardCallback); app->m_renderer->setCameraDistance(13); app->m_renderer->setCameraPitch(0); app->m_renderer->setCameraTargetPosition(0,0,0); b3SetCustomWarningMessageFunc(MyStatusBarWarning); b3SetCustomPrintfFunc(MyStatusBarPrintf); /* SimpleOpenGL3App* app = new SimpleOpenGL3App("AllBullet2Demos",width,height); s_instancingRenderer->setCameraDistance(13); s_instancingRenderer->setCameraPitch(0); s_instancingRenderer->setCameraTargetPosition(0,0,0); s_window->setMouseMoveCallback(MyMouseMoveCallback); s_window->setMouseButtonCallback(MyMouseButtonCallback); s_window->setKeyboardCallback(MyKeyboardCallback); */ assert(glGetError()==GL_NO_ERROR); gui = new GwenUserInterface; GL3TexLoader* myTexLoader = new GL3TexLoader; Gwen::Renderer::Base* gwenRenderer = 0; if (useOpenGL2) { gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); } else { sth_stash* fontstash=simpleApp->getFontStash(); gwenRenderer = new GwenOpenGL3CoreRenderer(simpleApp->m_primRenderer,fontstash,width,height,s_window->getRetinaScale(),myTexLoader); } // gui->init(width,height,gwenRenderer,s_window->getRetinaScale()); // gui->getInternalData()->m_explorerPage Gwen::Controls::TreeControl* tree = gui->getInternalData()->m_explorerTreeCtrl; //gui->getInternalData()->pRenderer->setTextureLoader(myTexLoader); MyProfileWindow* profWindow = setupProfileWindow(gui->getInternalData()); profileWindowSetVisible(profWindow,false); gui->setFocus(); #if 0 { MyGraphInput input(gui->getInternalData()); input.m_width=300; input.m_height=300; input.m_xPos = 0; input.m_yPos = height-input.m_height; input.m_name="Test Graph1"; input.m_texName = "graph1"; GraphingTexture* gt = new GraphingTexture; gt->create(256,256); int texId = gt->getTextureId(); myTexLoader->m_hashMap.insert("graph1", texId); //MyGraphWindow* gw = setupTextureWindow(input); } if (1) { MyGraphInput input(gui->getInternalData()); input.m_width=300; input.m_height=300; input.m_xPos = width-input.m_width; input.m_yPos = height-input.m_height; input.m_name="Test Graph2"; input.m_texName = "graph2"; GraphingTexture* gt = new GraphingTexture; int texWidth = 512; int texHeight = 512; gt->create(texWidth,texHeight); for (int i=0;i<texWidth;i++) { for (int j=0;j<texHeight;j++) { gt->setPixel(i,j,0,0,0,255); } } gt->uploadImageData(); int texId = gt->getTextureId(); input.m_xPos = width-input.m_width; myTexLoader->m_hashMap.insert("graph2", texId); //MyGraphWindow* gw = setupTextureWindow(input); } //destroyTextureWindow(gw); #endif s_parameterInterface = app->m_parameterInterface = new GwenParameterInterface(gui->getInternalData()); app->m_2dCanvasInterface = new QuickCanvas(myTexLoader); //gui->getInternalData()->m_demoPage; int numDemos = sizeof(allDemos)/sizeof(BulletDemoEntry); //char nodeText[1024]; //int curDemo = 0; int selectedDemo = loadCurrentDemoEntry(startFileName); Gwen::Controls::TreeNode* curNode = tree; MyMenuItemHander* handler2 = new MyMenuItemHander(-1); tree->onReturnKeyDown.Add(handler2, &MyMenuItemHander::onButtonD); for (int d = 0; d<numDemos; d++) { // sprintf(nodeText, "Node %d", i); Gwen::UnicodeString nodeUText = Gwen::Utility::StringToUnicode(allDemos[d].m_name); if (allDemos[d].m_menuLevel==1) { Gwen::Controls::TreeNode* pNode = curNode->AddNode(nodeUText); if (d == selectedDemo) { pNode->SetSelected(true); tree->ExpandAll(); selectDemo(d); } MyMenuItemHander* handler = new MyMenuItemHander(d); pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonA); pNode->GetButton()->onDoubleClick.Add(handler, &MyMenuItemHander::onButtonB); pNode->GetButton()->onDown.Add(handler, &MyMenuItemHander::onButtonC); pNode->onSelect.Add(handler, &MyMenuItemHander::onButtonE); pNode->onReturnKeyDown.Add(handler, &MyMenuItemHander::onButtonG); pNode->onSelectChange.Add(handler, &MyMenuItemHander::onButtonF); // pNode->onKeyReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->GetButton()->onKeyboardReturn.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onNamePress.Add(handler, &MyMenuItemHander::onButtonD); // pNode->onKeyboardPressed.Add(handler, &MyMenuItemHander::onButtonD); // pNode->OnKeyPress } else { curNode = tree->AddNode(nodeUText); } } /* for (int i=0;i<numDemos;i++) { allNames.push_back(allDemos[i].m_name); } */ //selectDemo(loadCurrentDemoEntry(startFileName)); /* gui->registerComboBox(DEMO_SELECTION_COMBOBOX,allNames.size(),&allNames[0],sCurrentDemoIndex); //const char* names2[] = {"comboF", "comboG","comboH"}; //gui->registerComboBox(2,3,&names2[0],0); gui->setComboBoxCallback(MyComboBoxCallback); */ unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds(); gui->registerFileOpenCallback(fileOpenCallback); do { assert(glGetError()==GL_NO_ERROR); s_instancingRenderer->init(); DrawGridData dg; dg.upAxis = app->getUpAxis(); { BT_PROFILE("Update Camera"); s_instancingRenderer->updateCamera(dg.upAxis); } if (renderGrid) { BT_PROFILE("Draw Grid"); app->drawGrid(dg); } static int frameCount = 0; frameCount++; if (0) { BT_PROFILE("Draw frame counter"); char bla[1024]; sprintf(bla,"Frame %d", frameCount); app->drawText(bla,10,10); } if (sCurrentDemo) { if (!pauseSimulation) { unsigned long int curTimeInMicroseconds = clock.getTimeMicroseconds(); unsigned long int diff = curTimeInMicroseconds-prevTimeInMicroseconds; float deltaTimeInSeconds = (diff)*1.e-6; //printf("---------------------------------------------------\n"); //printf("Framecount = %d\n",frameCount); sCurrentDemo->stepSimulation(deltaTimeInSeconds);//1./60.f); prevTimeInMicroseconds = curTimeInMicroseconds; } if (renderVisualGeometry) { if (visualWireframe) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } BT_PROFILE("Render Scene"); sCurrentDemo->renderScene(); } { glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); sCurrentDemo->physicsDebugDraw(gDebugDrawFlags); } } static int toggle = 1; if (1) { if (!pauseSimulation) processProfileData(profWindow,false); { if (useOpenGL2) { saveOpenGLState(width,height); } BT_PROFILE("Draw Gwen GUI"); gui->draw(s_instancingRenderer->getScreenWidth(),s_instancingRenderer->getScreenHeight()); if (useOpenGL2) { restoreOpenGLState(); } } } toggle=1-toggle; { BT_PROFILE("Sync Parameters"); s_parameterInterface->syncParameters(); } { BT_PROFILE("Swap Buffers"); app->swapBuffer(); } gui->forceUpdateScrollBars(); } while (!s_window->requestedExit()); // selectDemo(0); delete gui; delete app; return 0; }