int main(int argc, char* argv[]) { CommandLineArgs args(argc,argv); if (args.CheckCmdLineFlag("help")) { Usage(); return 0; } args.GetCmdLineArgument("enable_interop", useInterop); printf("useInterop=%d\n",useInterop); args.GetCmdLineArgument("pause_simulation", pauseSimulation); printf("pause_simulation=%d\n",pauseSimulation); args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X); args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y); args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z); args.GetCmdLineArgument("x_gap", X_GAP); args.GetCmdLineArgument("y_gap", Y_GAP); args.GetCmdLineArgument("z_gap", Z_GAP); printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z); printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP); args.GetCmdLineArgument("enable_static", keepStaticObjects); printf("enable_static=%d\n",keepStaticObjects); char* tmpfile = 0; args.GetCmdLineArgument("load_bulletfile", tmpfile ); if (tmpfile) fileName = tmpfile; printf("load_bulletfile=%s\n",fileName); printf("\n"); #ifdef __APPLE__ MacOpenGLWindow* window = new MacOpenGLWindow(); window->init(g_OpenGLWidth,g_OpenGLHeight); #else Win32OpenGLWindow* window = new Win32OpenGLWindow(); btgWindowConstructionInfo wci; wci.m_width = g_OpenGLWidth; wci.m_height = g_OpenGLHeight; window->createWindow(wci); window->setWindowTitle("render test"); #endif float retinaScale = 1; #ifndef __APPLE__ GLenum err = glewInit(); #else retinaScale = window->getRetinaScale(); #endif window->runMainLoop(); window->startRendering(); window->endRendering(); int maxObjectCapacity=128*1024; GLInstancingRenderer render(maxObjectCapacity); sth_stash* stash = initFont(); render.InitShaders(); createSceneProgrammatically(render); render.writeTransforms(); window->runMainLoop(); window->setMouseButtonCallback(MyMouseButtonCallback); window->setMouseMoveCallback(MyMouseMoveCallback); window->setResizeCallback(MyResizeCallback); window->setKeyboardCallback(btDefaultKeyboardCallback); window->setWheelCallback(btDefaultWheelCallback); GLPrimitiveRenderer* pprender = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight); glUseProgram(0); //////////////////////////////// setupGUI(g_OpenGLWidth,g_OpenGLHeight,stash,retinaScale); ///////////////////////////////////// if (pCanvas) { pCanvas->SetSize(g_OpenGLWidth,g_OpenGLHeight); } class CProfileIterator* m_profileIterator; m_profileIterator = CProfileManager::Get_Iterator(); glClearColor(1,1,1,1); while (!window->requestedExit()) { CProfileManager::Reset(); { BT_PROFILE("loop"); if (shootObject) { shootObject = false; btVector3 linVel;// = (m_cameraPosition-m_cameraTargetPosition).normalize()*-100; int x,y; window->getMouseCoordinates(x,y); render.getMouseDirection(&linVel[0],x,y); linVel.normalize(); linVel*=100; // btVector3 startPos; float orn[4] = {0,0,0,1}; float pos[4]; render.getCameraPosition(pos); // demo.setObjectTransform(pos,orn,0); //render.writeSingleInstanceTransformToGPU(pos,orn,0); // createScene(render, demo); // printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances); // printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances); // render.writeTransforms(); } { BT_PROFILE("startRendering"); window->startRendering(); } render.RenderScene(); glFinish(); float col[4]={0,1,0,1}; // pprender->drawRect(10,50,120,60,col); // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); //glEnable(GL_TEXTURE_2D); float x = 10; float y=220; float dx=0; if (0) { BT_PROFILE("font sth_draw_text"); sth_begin_draw(stash); sth_flush_draw(stash); sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale); if (retinaScale!=1.f) sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale); sth_flush_draw(stash); sth_end_draw(stash); } if (1) { BT_PROFILE("gwen RenderCanvas"); if (pCanvas) { glEnable(GL_BLEND); GLint err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); //glColor4ub(255,0,0,255); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glEnable(GL_BLEND); err = glGetError(); assert(err==GL_NO_ERROR); pCanvas->RenderCanvas(); //restoreOpenGLState(); } } window->endRendering(); } CProfileManager::Increment_Frame_Counter(); static bool printStats = true; if (printStats && !pauseSimulation) { static int count = 0; count--; if (count<0) { count = 100; { //BT_PROFILE("processProfileData"); processProfileData(m_profileIterator,false); } //CProfileManager::dumpAll(); //printStats = false; } else { // printf("."); } } } delete pprender; // render.CleanupShaders(); #ifdef _WIN32 window->closeWindow(); #else window->exit(); #endif delete window; 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; }
void OpenGLExampleBrowser::update(float deltaTime) { b3ChromeUtilsEnableProfiling(); B3_PROFILE("OpenGLExampleBrowser::update"); assert(glGetError()==GL_NO_ERROR); s_instancingRenderer->init(); DrawGridData dg; dg.upAxis = s_app->getUpAxis(); { BT_PROFILE("Update Camera and Light"); s_instancingRenderer->updateCamera(dg.upAxis); } static int frameCount = 0; frameCount++; if (0) { BT_PROFILE("Draw frame counter"); char bla[1024]; sprintf(bla,"Frame %d", frameCount); s_app->drawText(bla,10,10); } if (gPngFileName) { static int skip = 0; skip--; if (skip<0) { skip=gPngSkipFrames; //printf("gPngFileName=%s\n",gPngFileName); static int s_frameCount = 100; sprintf(staticPngFileName,"%s%d.png",gPngFileName,s_frameCount++); //b3Printf("Made screenshot %s",staticPngFileName); s_app->dumpNextFrameToPng(staticPngFileName); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } if (sCurrentDemo) { if (!pauseSimulation || singleStepSimulation) { //printf("---------------------------------------------------\n"); //printf("Framecount = %d\n",frameCount); B3_PROFILE("sCurrentDemo->stepSimulation"); if (gFixedTimeStep>0) { sCurrentDemo->stepSimulation(gFixedTimeStep); } else { sCurrentDemo->stepSimulation(deltaTime);//1./60.f); } } if (renderGrid) { BT_PROFILE("Draw Grid"); glPolygonOffset(3.0, 3); glEnable(GL_POLYGON_OFFSET_FILL); s_app->drawGrid(dg); } if (renderVisualGeometry && ((gDebugDrawFlags&btIDebugDraw::DBG_DrawWireframe)==0)) { if (visualWireframe) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); } BT_PROFILE("Render Scene"); sCurrentDemo->renderScene(); } //else { B3_PROFILE("physicsDebugDraw"); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); sCurrentDemo->physicsDebugDraw(gDebugDrawFlags); } } { if (gui2 && s_guiHelper && s_guiHelper->getRenderInterface() && s_guiHelper->getRenderInterface()->getActiveCamera()) { B3_PROFILE("setStatusBarMessage"); char msg[1024]; float camDist = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraDistance(); float pitch = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraPitch(); float yaw = s_guiHelper->getRenderInterface()->getActiveCamera()->getCameraYaw(); float camTarget[3]; 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]); gui2->setStatusBarMessage(msg, true); } } static int toggle = 1; if (renderGui) { B3_PROFILE("renderGui"); #ifndef BT_NO_PROFILE if (!pauseSimulation || singleStepSimulation) { if (isProfileWindowVisible(s_profWindow)) { processProfileData(s_profWindow,false); } } #endif //#ifndef BT_NO_PROFILE if (sUseOpenGL2) { saveOpenGLState(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight()); } if (m_internalData->m_gui) { gBlockGuiMessages = true; m_internalData->m_gui->draw(s_instancingRenderer->getScreenWidth(), s_instancingRenderer->getScreenHeight()); gBlockGuiMessages = false; } if (sUseOpenGL2) { restoreOpenGLState(); } } singleStepSimulation = false; toggle=1-toggle; { BT_PROFILE("Sync Parameters"); if (s_parameterInterface) { s_parameterInterface->syncParameters(); } } { BT_PROFILE("Swap Buffers"); s_app->swapBuffer(); } if (gui2) { B3_PROFILE("forceUpdateScrollBars"); gui2->forceUpdateScrollBars(); } }
bool DBGNet::processHeader(DBGHeader* header) { if(header->sync() != DBGSYNC) { error("Network sync error."); return false; } //TODO: create dbgStarted() and dbgStepDone() to organize this. switch(header->cmd()) { case DBGC_REPLY: break; case DBGC_END: break; case DBGC_EMBEDDED_BREAK: break; case DBGC_ERROR: if(m_isProfiling) { error("PHP could not execute the script. Check for errors before running the profiler."); return false; } break; case DBGC_LOG: case DBGC_SID: case DBGC_PAUSE: break; case DBGC_STARTUP: //so lets start too... m_requestor->addHeaderFlags(DBGF_STARTED); //...sending options... m_requestor->requestOptions(m_opts); //...tell everyone we are running. if(!m_isProfiling) { emit sigDBGStarted(); } //...fancy notification on taskbar KNotifyClient::userEvent(0, "", KNotifyClient::Taskbar); if(m_isProfiling) { m_requestor->requestStepInto(); //get module info // m_requestor->requestSrcTree(); //get frequency info m_requestor->requestProfileFreqData(TEST_LOOPS); //get lines info to set temp breakpoint on the last valid line m_requestor->requestSrcLinesInfo(1); break; } if(!(m_opts & SOF_BREAKONLOAD)) { //workaround for my lazyness (I don't know why setting SOF_BREAKONLOAD //is not enough to avoid the load break) m_requestor->requestContinue(); } else { //...asking for module information.. m_requestor->requestSrcTree(); //workaround for the double step on the begginning //is annoying having to step twice in the begginig. Lets do the the first. m_requestor->requestStepInto(); } break; case DBGC_BREAKPOINT: if(!m_isProfiling) { emit sigBreakpoint(); processStepData(); } else { processProfileData(); } break; case DBGC_STEPINTO_DONE: case DBGC_STEPOVER_DONE: case DBGC_STEPOUT_DONE: if(!m_isProfiling) { emit sigStepDone(); processStepData(); } break; } return true; }