void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); fpsCurrentTime = glfwGetTime(); noFrames++; if (fpsCurrentTime - fpsLastTime >= 1.0) { myfile << "ms/frame " << 1000.0 / double(noFrames) << std::endl; noFrames = 0; fpsLastTime += 1.0; } drawCubeMap(); drawTerrain(); drawVegetation(); doMovements(); glutSwapBuffers(); lastTime = currentTime; }
/** * This method is used to draw the scene. */ void GLWindow::draw(){ //clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //we will now place the camera setupGLCamera(); //and set up the lights (do this so that the position is specified in world coordinates, not in camera ones). setupLights(); /** If we want fog... */ /* GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f}; // Fog Color glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode glFogfv(GL_FOG_COLOR, fogColor); // Set Fog Color glFogf(GL_FOG_DENSITY, 0.35f); // How Dense Will The Fog Be glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value glFogf(GL_FOG_START, 20.0f); // Fog Start Depth glFogf(GL_FOG_END, 80.0f); // Fog End Depth glEnable(GL_FOG); // Enables GL_FOG */ if (Globals::drawCubeMap) drawCubeMap(); glColor3d(1, 1, 1); //and then draw the application stuff if (Globals::app) Globals::app->draw(); if (Globals::drawGroundPlane && Globals::app) Globals::app->drawGround(); //no more texture mapping or lighting needed glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); if (Globals::drawShadows && Globals::drawGroundPlane && Globals::app) drawShadows(); glColor3d(1,1,1); if (Globals::app) Globals::app->drawExtras(); if (Globals::drawGlobalAxes) drawAxes(); //wait until the required ammount of time has passed (respect the desired FPS requirement) while (fpsTimer.timeEllapsed()<1.0/Globals::desiredFrameRate); if (Globals::drawFPS) drawFPSandPerf(fpsTimer.timeEllapsed(), timeSpentProcessing/(1/Globals::desiredFrameRate)); //print a screenshot if needed if (Globals::drawScreenShots){ static int screenShotNumber = 0; char fName[100]; sprintf(fName, "..\\screenShots\\ss%05d.bmp", screenShotNumber); screenShotNumber++; GLUtils::saveScreenShot(fName, 0, 0, w, h); } if (Globals::drawWorldShots && Globals::app ){ static int worldShotNumber = 0; char fName[100]; sprintf(fName, "..\\worldShots\\ws%05d.obj", worldShotNumber); worldShotNumber++; FILE* fp = fopen( fName, "w" ); fprintf( fp, "####\n" "#\n" "# OBJ File Generated by UBC-IMAGER character animation tool\n" "# Frame %05d\n" "#\n" "####\n\n", worldShotNumber ); Globals::app->renderToObjFile( fp, 0 ); fclose( fp ); } fpsTimer.restart(); }
//-------------------------------------------------------------- void ofApp::draw(){ embossFbo.begin(); ofPushMatrix(); ofTranslate(0,0,ofMap(pad->getPoint().x, 0.0,w,1.0,20));//1.979); //ofRotate(-0.019 * -hueCycle, 1, 0, 1); embossShader.begin(); embossShader.setUniformTexture("src_tex_unit0", fbTex, 0); embossShader.setUniform1f("imgWidth", ofGetWidth()); embossShader.setUniform1f("imgHeight", ofGetHeight()); embossShader.setUniform1f("step_w", ofMap(pad->getPoint().y,0,h, 1.0/ofGetWidth(), 1.0/ofGetWidth()*20) ); embossShader.setUniform1f("step_h", ofMap(pad->getPoint().y,0,h, 1.0/ofGetHeight(), 1.0/ofGetHeight()*20) ); embossShader.setUniform1f("angry", angryButton->getValue()); fbTex.draw(0,0); embossShader.end(); ofPopMatrix(); embossFbo.end(); for(int i = 0; i<2; i++){ ofTexture tex; if(i == 0){ tex = embossFbo.getTexture(); } else{ tex = embossBlurVFbo.getTexture(); } embossBlurHFbo.begin(); blurHShader.begin(); blurHShader.setUniformTexture("s_texture", tex, 0); tex.draw(0,0); blurHShader.end(); embossBlurHFbo.end(); embossBlurVFbo.begin(); blurVShader.begin(); blurVShader.setUniformTexture("s_texture", embossBlurHFbo.getTexture(), 0); embossBlurHFbo.draw(0,0); blurVShader.end(); embossBlurVFbo.end(); } //embossFbo.readToPixels(fbPix); //fbTex.loadData(fbPix); fbTex = embossFbo.getTexture(); //end feedback loop //animation settings///////////////////////////////////////////////////// colorMixPct = ofClamp(ofMap(frameCounter, boom, boom+2000, 0, 1), 0, 1); //colorMixPct = ofClamp(ofMap(frameCounter, endBoom, endFrame, 0, 1), 0, 1); colorMix = (( 1.0 - colorMixPct) * 0.2 ) + (colorMixPct * 1); fadeInColor = ofxTween::map(frameCounter, boom, boom+2000, 0.6, 1.0, true, easingCubic, ofxTween::easeInOut); hueCycle = 0.9;//ofxTween::map(frameCounter, boom+150, goodBye-75, 1.0, -30.1, true, easingCubic, ofxTween::easeInOut); //fogOscPct = ofClamp(ofMap(frameCounter, beginFrame, endFrame, 0, 1), 0, 1); //fogOsc = (( 1.0 - fogOscPct) * -1 ) + (fogOscPct * 0); fogOsc = ofxTween::map(frameCounter, boom, boom+2000, 0.7, 0.2, true, easingCubic, ofxTween::easeInOut); texScale = ofxTween::map(frameCounter, hello+75, boom+3000, 30.0, 1.0, true, easingCubic, ofxTween::easeOut); zScale = ofxTween::map(frameCounter, hello+95, boom+3000, 30.0, 1.0, true, easingCubic, ofxTween::easeOut); //angryPct = ofClamp(ofMap(frameCounter, boom, 6732, 0, 1), 0, 1); angryPct = ofxTween::map(frameCounter, boom, boom+1000, 0.0, 1.0, true, easingCubic, ofxTween::easeInOut); increaseDisp = ofxTween::map(frameCounter, boom, boom+1000, 0, 15, true, easingCubic, ofxTween::easeInOut); //increaseDisp = ofxTween::map(frameCounter, boom, 6762, 0, -500, true, easingCubic, ofxTween::easeInOut); //angryMix = 0.0; spikyMix = ofxTween::map(frameCounter, endFrame-90, endFrame-30, 0.0, 0.5, true, easingLinear, ofxTween::easeIn); if(frameCounter > boom && frameCounter < endBoom + 20){ //angryMix = ((1.0 - angryPct) * 0.0 ) + (angryPct * 1.0); angryMix = angryPct; isAngry = true; } else if (frameCounter >= endBoom + 20){ angryMix -= 0.0025; angryMix = ofClamp(angryMix, 0.0, 1.0); increaseDisp = ofxTween::map(frameCounter, boom+10, endFrame, 15, 15, true, easingCubic, ofxTween::easeInOut); } dispPct = ofClamp(ofMap(frameCounter, beginFrame, endFrame*10, 0, 1), 0, 1); dispAmt = ((1.0 - dispPct) * 10.0 ) + (dispPct * 10.0); beatHitPct = ofClamp(ofMap(frameCounter, boom, endFrame*10, 0, 1), 0, 1); beatHit = ((1.0 - beatHitPct) * 1.0) + (beatHitPct * 1.15); fogPct = ofClamp(ofMap(frameCounter, beginFrame, goodBye+1000, 0, 1), 0, 1); fogDist = ((1.0 - fogPct) * 500000 ) + (fogPct * 400000); if(frameCounter >= beginFrame && frameCounter < boom ){ // fogDist = ofxTween::map(frameCounter, beginFrame, boom, 500000, 600000, true, easingCubic, ofxTween::easeOut); } if(frameCounter < beginFrame){ fogDist = ofxTween::map(frameCounter, hello+55, beginFrame, 2500000, 500000, true, easingCubic, ofxTween::easeOut); } fadeToBlack = 1.0; if(frameCounter >= goodBye - 150 ){ fogPct = ofClamp(ofMap(frameCounter, goodBye-150, goodBye-100, 0, 1), 0, 1); fogDist = ((1.0 - fogPct) * 400000 ) + (fogPct * 100); fadeToBlack = ((1.0 - fogPct) * 1 ) + (fogPct * 0); } /////////////////////////////////////////////////////////////// if(!renderCubeMap){ sceneFbo.begin(); cam.begin(); draw3dScene(); cam.end(); sceneFbo.end(); pp = postProcess(sceneFbo.getTexture()); pp.draw(0,0); //pp.readToPixels(savePix); //ofSaveImage(savePix, "chap11FlyThrough3/chap11FlyThrough_"+ofToString(frameCounter)+".jpg"); //sceneFbo.draw(0,0); } else if(renderCubeMap){ drawCubeMap(); } if(ofGetKeyPressed('r')){ embossFbo.draw(0,0); } // ofSetColor(0); // ofDrawRectangle(25,15,50,20); // ofSetColor(255); // ofDrawBitmapString(ofToString(frameCounter), 30,30); wait++; if(wait > 0){ frameCounter++; } }