/** * @function redisplay * (Called at each openGL step) * - Processes the webcam frame to detect the eyes with OpenCV, * - Creates a 3D scene with OpenGL, * - Render the scene and the webcam image. */ void redisplay() { if(frame.empty()) return; if(!bPause) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // OPENCV //-- flip frame image cv::Mat tempimage; if(bInvertCam) cv::flip(frame, tempimage, 0); else cv::flip(frame, tempimage, 1); //-- detect eyes tempimage = detectEyes(tempimage); // OPENGL //-- scene setGlCamera(); draw3dScene(); //-- cam if(bDisplayCam) displayCam(tempimage); // RENDER glutSwapBuffers(); } //-- post the next redisplay glutPostRedisplay(); }
//-------------------------------------------------------------- void ofApp::drawCubeMap(){ ofTexture pp, pp2, pp3, pp4, pp5, pp6; saveFbo.begin(); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[0], axis[0])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp = postProcess(cubeFbo.getTexture()); pp.draw(cubeSize, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[1], axis[1])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp2 = postProcess(cubeFbo.getTexture()); pp2.draw(cubeSize, 0, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[2], axis[2])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp3 = postProcess(cubeFbo.getTexture()); pp3.draw(cubeSize, cubeSize*2, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[3], axis[3])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp4 = postProcess(cubeFbo.getTexture()); pp4.draw(cubeSize*2, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[4], axis[4])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp5 = postProcess(cubeFbo.getTexture()); pp5.draw(cubeSize*3, cubeSize, cubeSize, cubeSize); cubeCamera.setGlobalPosition(0, 0, 0); cubeFbo.begin(); ofClear(0); cubeCamera.setOrientation(ofQuaternion(degrees[5], axis[5])); cubeCamera.begin(); draw3dScene(); cubeCamera.end(); cubeFbo.end(); pp6 = postProcess(cubeFbo.getTexture()); pp6.draw(0,cubeSize, cubeSize, cubeSize); saveFbo.end(); saveFbo.readToPixels(savePix); ofSaveImage(savePix, "cubeImages/final/ch13_"+ofToString(inc)+".tga"); inc++; saveFbo.draw(0,0, w, h); //video.nextFrame(); }
//-------------------------------------------------------------- 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++; } }