void CloudsVisualSystemCities::selfUpdate() { ofPushStyle(); ofSetColor(255); int texWidth = noiseFbo.getWidth(); int texHeight = noiseFbo.getHeight(); noiseFbo.begin(); ofClear(0); noiseShader.begin(); noiseShader.setUniform2f("resolution", texWidth,texHeight); noiseShader.setUniform1f("time", ofGetElapsedTimef()*noiseSpeed); noiseShader.setUniform1f("zoom", noiseZoom); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(texWidth, 0); glVertex3f(texWidth, 0, 0); glTexCoord2f(texWidth, texHeight); glVertex3f(texWidth, texHeight, 0); glTexCoord2f(0,texHeight); glVertex3f(0,texHeight, 0); glEnd(); noiseShader.end(); noiseFbo.end(); if(bGrayscott){ if (bCleanGrayscott){ for (int i = 0; i < 2; i++) { grayscottFbo[i].begin(); ofClear(0); grayscottFbo[i].end(); } bCleanGrayscott = false; } for (int i = 0; i < grayscottLoops; i++) { nPingPong = (nPingPong+1)%2; grayscottFbo[nPingPong%2].begin(); grayscottShader.begin(); grayscottShader.setUniformTexture("backbuffer", grayscottFbo[(nPingPong+1)%2], 1); grayscottShader.setUniformTexture("tex0", noiseFbo, 2); grayscottShader.setUniform1f("diffU", diffU); grayscottShader.setUniform1f("diffV", diffV); grayscottShader.setUniform1f("k", k); grayscottShader.setUniform1f("f", f); grayscottShader.setUniform1f("time", ofGetElapsedTimef()); grayscottShader.setUniform1f("fade", grayscottFade); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(texWidth, 0); glVertex3f(texWidth, 0, 0); glTexCoord2f(texWidth, texHeight); glVertex3f(texWidth, texHeight, 0); glTexCoord2f(0,texHeight); glVertex3f(0,texHeight, 0); glEnd(); grayscottShader.end(); grayscottFbo[nPingPong%2].end(); } } maskFbo.begin(); ofClear(0); maskShader.begin(); maskShader.setUniform2f("resolution", texWidth, texHeight); maskShader.setUniform1f("size", maskSize); maskShader.setUniform1f("curve",maskCurve); if(bGrayscott){ grayscottFbo[nPingPong%2].draw(0, 0); } else { noiseFbo.draw(0, 0); } maskShader.end(); maskFbo.end(); ofPopStyle(); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetLineWidth(lineW); glPointSize(lineW); //glEnable(GL_NORMALIZE); gpuBlur.beginDrawScene(); ofClear(0, 0, 0, 0); cam.begin(); light.enable(); glEnable(GL_DEPTH_TEST); //glShadeModel(GL_FLAT); ofSetColor(255); light.draw(); ofEnableLighting(); ofSetSphereResolution(4); flock->draw(); glDisable(GL_COLOR_MATERIAL); TIME_SAMPLE_START("drawWorms"); ofEnableBlendMode(OF_BLENDMODE_ADD); ofEnableBlendMode(OF_BLENDMODE_ALPHA); mMatMainMaterial.begin(); if(doShader){ shader->begin(); shader->setUniform1f("shaderVal1", 1); shader->setUniform1f("shaderVal2", 1); shader->setUniform1f("shaderVal3", 1); shader->setUniform1f("time", ofGetElapsedTimef() ); shader->setUniform1f("specularGain", specularGain); shader->setUniform1f("specularClamp", specularClamp); shader->setUniform1f("specularPow", specularPow); shader->setUniform1f("eyeSpecularGain", eyeSpecularGain); shader->setUniform1f("eyeSpecularClamp", eyeSpecularClamp); shader->setUniform1f("eyeSpecularPow", eyeSpecularPow); shader->setUniform1f("showInShader", showInShader); } if(drawTeapot) glutSolidTeapot(80); if(drawTrails){ for(int i = 0; i < NUM_FISH_PER_FLOCK; i++){ t[i].draw(); } } if(doShader){ shader->end(); } mMatMainMaterial.end(); ofDisableLighting(); TIME_SAMPLE_STOP("drawWorms"); ofDrawAxis(10); ofSetColor(255); glDisable(GL_DEPTH_TEST); cam.end(); gpuBlur.endDrawScene(); ofSetColor(255); ofEnableBlendMode(OF_BLENDMODE_ALPHA); gpuBlur.performBlur(); //draw clean scene ofSetColor(255); ofBackgroundGradient(ofColor::fromHsb(160, 255, 60), ofColor::fromHsb(0, 0, 0)); ofEnableBlendMode(OF_BLENDMODE_ALPHA); gpuBlur.drawSceneFBO(); ofEnableBlendMode(OF_BLENDMODE_ADD); //overlay the blur gpuBlur.drawBlurFbo(); ofSetColor(255); }
void AlphaMask::maskRect(){ int srcMargin = 100; ofApp *app = ((ofApp*)ofGetAppPtr()); srcTex = app->blackmagic->colorTexture; ofFbo srcFbo; srcFbo.allocate(1920, 1080 / 2.0); srcFbo.begin(); ofClear(0, 0, 0); ofPushMatrix(); //ofScale(1.0, 0.5); srcTex.draw(0, 0, 1920, 1080 / 2.0); ofPopMatrix(); srcFbo.end(); fbo.begin(); ofClear(0, 0, 0); maskShader.begin(); glActiveTexture(GL_TEXTURE0_ARB); srcFbo.getTextureReference().bind(); glActiveTexture(GL_TEXTURE1_ARB); rectMask[rectMaskNum].getTextureReference().bind(); glBegin(GL_QUADS); float maskOffsetX = ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getWidth(), mask.getWidth() / 4.5); //float maskOffsetY = ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getHeight(), mask.getHeight() / 4.5); float maskOffsetY = ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getWidth(), mask.getWidth() / 4.5); glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0); glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, maskOffsetY); glVertex2f(400, 223); glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), 0); glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, maskOffsetY); glVertex2f(1520, 223); glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), srcTex.getHeight() / 2.0); glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, mask.getHeight() - maskOffsetY); glVertex2f(1520, 856); glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, srcTex.getHeight() / 2.0); glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, mask.getHeight() - maskOffsetY); glVertex2f(400, 856); glEnd(); glActiveTexture(GL_TEXTURE1_ARB); rectMask[rectMaskNum].getTextureReference().unbind(); glActiveTexture(GL_TEXTURE0_ARB); srcFbo.getTextureReference().unbind(); maskShader.end(); fbo.end(); ofSetColor(255, app->oscControl->controlVal[2] * 2); fbo.draw(0, 0); }
void ofxFlocking::update(ofTexture &normalTex, ofTexture &obstaclesTex, ofTexture &foodTex){ int actual = (frame)%2; // Actual buffer int prev = (frame+1)%2; // Prev/Next buffer // 2. Update Velocities velFbo[actual].begin(); ofClear(0); velUpdateShader.begin(); velUpdateShader.setUniformTexture("posData", posFbo[prev].getTextureReference(), 0); velUpdateShader.setUniformTexture("prevVelData", velFbo[prev].getTextureReference(), 1); velUpdateShader.setUniformTexture("normalTex", normalTex, 2); velUpdateShader.setUniformTexture("obstacleTex", obstaclesTex, 3); velUpdateShader.setUniformTexture("foodTex", foodTex, 4); velUpdateShader.setUniform1i("resolution", (int)resolution); velUpdateShader.setUniform2f("screen", (float)width, (float)height); velUpdateShader.setUniform1f("timestep", data->biosphereTimeStep); velUpdateShader.setUniform1f("minDist", data->biosphereMinDist); velUpdateShader.setUniform1f("maxDist", data->biosphereMaxDist); velUpdateShader.setUniform1f("maxSpeed", data->biosphereMaxSpeed); velUpdateShader.setUniform1f("maxForce", data->biosphereMaxForce); velUpdateShader.setUniform1f("separation", data->biosphereSeparation); velUpdateShader.setUniform1f("alineation", data->biosphereAlineation); velUpdateShader.setUniform1f("cohesion", data->biosphereCohesion); velUpdateShader.setUniform1f("borders", data->biosphereBorders); //velUpdateShader.setUniform1f("flat", data->biosphereFlat); //velUpdateShader.setUniform1f("food", data->biosphereFood); renderFrame(resolution,resolution); velUpdateShader.end(); velFbo[actual].end(); // 3. Update Positions posFbo[actual].begin(); ofClear(0); posUpdateShader.begin(); posUpdateShader.setUniformTexture("prevPosData", posFbo[prev].getTextureReference(), 0); posUpdateShader.setUniformTexture("velData", velFbo[actual].getTextureReference(), 1); posUpdateShader.setUniform1f("timestep",(float) timeStep ); renderFrame(resolution,resolution); posUpdateShader.end(); posFbo[actual].end(); posFbo[actual].readToPixels(pixels); for(int x = 0; x < resolution; x++){ for(int y = 0; y < resolution; y++){ ofFloatColor p = pixels.getColor(x, y); int i = y * resolution + x; particles[i].set(p.r,p.g,p.b); } } // 4. sort for alpha blending (optional) // 5. Transfer texture data to vertex data renderFbo.begin(); ofClear(0); renderShader.begin(); renderShader.setUniformTexture("posTex", posFbo[actual].getTextureReference(), 0); renderShader.setUniformTexture("sparkTex", sparkImage.getTextureReference() , 1); renderShader.setUniform1i("resolution", (int)resolution); renderShader.setUniform2f("screen", (float)width, (float)height); renderShader.setUniform1f("size", (float)particleSize); renderShader.setUniform1f("imgWidth", (float)sparkImage.getWidth()); renderShader.setUniform1f("imgHeight", (float)sparkImage.getHeight()); ofEnableBlendMode( OF_BLENDMODE_ADD ); ofSetColor(255); glBegin( GL_POINTS ); for(int i = 0; i < nBoids; i++){ glVertex3d(particles[i].x, particles[i].y, particles[i].z); } ofDisableBlendMode(); glEnd(); renderShader.end(); renderFbo.end(); ofEnableBlendMode( OF_BLENDMODE_ALPHA ); // Switch buffers frame++; }
void testApp::standardDraw() { //aberration = ofMap(mouseX, 0, targetWidth, 0, 1); //pointBrightness = ofMap(mouseY, 0, targetHeight(), 0, 1); //DO NOT F-ING DELETE THIS MOFOS :) ofEnableAlphaBlending(); chroma.begin(); float fov = panel.getValueF("fov"); float dist = connexionCamera.getZoom(); ofSetupScreenPerspective(ofGetWidth(), ofGetHeight(), OF_ORIENTATION_DEFAULT, false, fov, dist / 1000.f, dist * 1000.f); connexionCamera.minZoom = panel.getValueF("minZoom"); connexionCamera.maxZoom = panel.getValueF("maxZoom"); ofPushStyle(); if( ofGetFrameNum() < 20 || !panel.getValueB("do_trails") ){ ofClear(0, 0, 0, 255); }else{ ofSetColor(0, 0, 0, ofMap(connexionCamera.quaternionChangeAmount, 0,panel.getValueF("fboScale"), 255,100, true)); ofFill(); ofRect(0, 0, targetWidth, targetHeight); } ofPopStyle(); ofPushMatrix(); connexionCamera.draw(mouseX, mouseY, !panel.getValueB("bFreezeParticles")); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0); // super helpful: http://pmviewer.sourceforge.net/method.php glEnable(GL_POINT_SMOOTH); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); dofShader.begin(); float rgbBrightness = panel.getValueF("rgbBrightness"); dofShader.setUniform1f("focusDistance", (panel.getValueB("smartFocalPlane") ? connexionCamera.getZoom() : 0) + panel.getValueF("focus_offset")); dofShader.setUniform1f("aperture", aperture); dofShader.setUniform1f("pointBrightness", pointBrightness); dofShader.setUniform1f("rgbBrightness", rgbBrightness); dofShader.setUniform1f("maxPointSize", panel.getValueF("maxPointSize")); if (panel.getValueB("bDrawParticles")){ glPushMatrix(); glScalef(1 / frameScaleFactor, 1 / frameScaleFactor, 1 / frameScaleFactor); PS.drawAll(); glPopMatrix(); } dofShader.end(); float sphereSize = 10000; sphereShader.begin(); sphereShader.setUniform1f("alpha", panel.getValueF("sphere_alpha")); sphereShader.setUniform1f("redScale", panel.getValueF("sphere_red")); sphereShader.setUniform1f("greenScale", panel.getValueF("sphere_green")); sphereShader.setUniform1f("blueScale", panel.getValueF("sphere_blue")); glColor4f(1, 1, 1, panel.getValueF("sphere_alpha")); ofFill(); ofRotateX(-90); ofSphere(sphereSize); sphereShader.end(); ofPopMatrix(); // clear the alpha on the fbo glColorMask(0, 0, 0, 1); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); glColorMask(1, 1, 1, 1); chroma.end(); drawWithAberration(); SP.draw(); }
//-------------------------------------------------------------- void ofxMtlMapping2D::bind() { _fbo.bind(); ofClear(.0f, .0f, .0f, .0f); ofClearAlpha(); }
void TexturedObjectScrollView::setup(const ofRectangle& r, ScrollViewConfig cfg){ config = cfg; setPosition(ofVec2f(r.x, r.y)); Node::setSize(r.width, r.height); ofFbo::Settings fboSettings; fboSettings.width = r.width; fboSettings.height = r.height; fboSettings.useDepth = false; fboSettings.textureTarget = GL_TEXTURE_RECTANGLE_ARB; //mipmaps! fboSettings.internalformat = config.internalFormat; fboSettings.numSamples = config.numFboSamples; fboSettings.numColorbuffers = 1; fbo.allocate(fboSettings); //no antialias needed here? fbo.begin(); ofClear(0,0,0,0); fbo.end(); canvas.width = r.width; canvas.height = r.height; expandedCanvas = canvas; //used to control scrollview clipping expandedCanvas.x -= config.canvasLookAheadDist; expandedCanvas.width += config.canvasLookAheadDist * 2; scrollCanvas = expandedCanvas; xOffset = scrollInertia = 0.0f; touchID = -1; fboDirty = 0.2; autoScrolling = false; gradientR.clear(); gradientR.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); gradientR.addVertex(ofVec3f(r.width - config.scrollviewEdgeGradientWidth,0)); gradientR.addVertex(ofVec3f(r.width - config.scrollviewEdgeGradientWidth,r.height)); gradientR.addVertex(ofVec3f(r.width,0)); gradientR.addVertex(ofVec3f(r.width,r.height)); gradientR.addColor(ofColor(config.bgColor,0)); gradientR.addColor(ofColor(config.bgColor,0)); if(config.bgColor.a == 0){ gradientR.addColor(ofColor(config.bgColor,255)); gradientR.addColor(ofColor(config.bgColor,255)); }else{ gradientR.addColor(ofColor(config.bgColor)); gradientR.addColor(ofColor(config.bgColor)); } gradientL.clear(); gradientL.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); gradientL.addVertex(ofVec3f(0,0)); gradientL.addVertex(ofVec3f(0,r.height)); gradientL.addVertex(ofVec3f(config.scrollviewEdgeGradientWidth,0)); gradientL.addVertex(ofVec3f(config.scrollviewEdgeGradientWidth,r.height)); if(config.bgColor.a == 0){ gradientL.addColor(ofColor(config.bgColor,255)); gradientL.addColor(ofColor(config.bgColor,255)); }else{ gradientL.addColor(ofColor(config.bgColor)); gradientL.addColor(ofColor(config.bgColor)); } gradientL.addColor(ofColor(config.bgColor,0)); gradientL.addColor(ofColor(config.bgColor,0)); ofAddListener(eventTouchMove, this, &TexturedObjectScrollView::onTouchMove); ofAddListener(eventTouchUp, this, &TexturedObjectScrollView::onTouchUp); ofAddListener(eventTouchDown, this, &TexturedObjectScrollView::onTouchDown); }
//-------------------------------------------------------------- void ofApp::update(){ //openCV update///////////////////////////////////////////////////////////////////////////////////////////////////////// grabber.update(); //pull our next frame of video image.setFromPixels(grabber.getPixelsRef()); //set our CV Color Image to have the same data as the current frame greyImage = image; //convert our color image to grayscale greyDiff.absDiff(greyBackground, greyImage);//compare the difference of the background to a greyed version greyProcessed = greyDiff;//set our greyProcessed to the greyDiff greyProcessed.threshold(250);//threshold for finding light this is set high so that it can find fine light points contourFinder.findContours(greyProcessed, 40, (grabber.width*grabber.height)/2, maxBlobs, true);//using the graber find the contours of the blob if(contourFinder.nBlobs == 1) // if the number of detected blobs is 1 { drawPoint = true;//set draw point to be true to allow drawing createAlphaTrail(); if(particles.size()<maxParticles)//if the size of the vector of particles is less than the max allowed particles { createParticles();//create particles checkParticles();//check the size of the vector } } else { drawPoint = false;//if none of the above is true then remain false to avoid drawing when nothing is detected } for(int i = 0; i < contourFinder.nBlobs; i++)//go throught the blobs and send the information to a location point { blobCenters[i] = contourFinder.blobs[i].centroid; } //openCV end//////////////////////////////////////////////////////////////////////////////////////////////////////////// //audio update////////////////////////////////////////////////////////////////////////////////////////////////////////// scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);//map the smoothed volume to a sensible set of integers volHistory.push_back( scaledVol );//push the oldest volume recording in the vector if( volHistory.size() >= 400 )//if the volume history hits the cap of 400 erase the oldest volume recording { checkFreq();//check the recorded amount of frequencies } //audio end//////////////////////////////////////////////////////////////////////////////////////////////////////////// //visuals update/////////////////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i < particles.size(); i++) { particles[i].applyForce(wind);//apply the wind force to the big circle particles particles[i].applyForce(gravity);//apply the gravity force to the big circle particles particles[i].changeAlpha();//change the particle alpha particles[i].particleFlow();//run the particle flow function on every particle particles[i].particleMass = scaledVolInt;//set the current particles mass to be the current volume for variation particles[i].update();//update particles } particleLoc = blobLocation;//particle location is equal to the location of the blob found using the camera (must update) if(drawPoint) { screenFbo.begin();//start the FBO if(fboTimer == 0)//if the timer is 0 clear the FBO to give it a delayed alpha trail effect { ofClear(255, 255, 255);//clear the screen of the old particles fboTimer = 4;//after clearing reset the timer } screenFbo.end();//end the fbo screenFbo.begin(); ofEnableAlphaBlending(); for(int i = 0; i < particles.size(); i++)//loop through and draw the particles { particles[i].draw();//draw the particles particles[i].particleFlow();//call the flow function on the particles } screenFbo.end(); } //VISUALS end///////////////////////////////////////////////////////////////////////////////////////////////////////// }
//-------------------------------------------------------------- void testApp::setup() { //Set the background to black ofBackground( 0 , 0 , 0 ) ; //load our image inside bin/data image.loadImage ( "images/text.png" ) ; //if the app performs slowly raise this number sampling = 1 ; curImageIndex = 0 ; //Retrieve the pixels from the loaded image unsigned char * pixels = image.getPixels() ; //store width and height for optimization and clarity int w = image.width ; int h = image.height ; //offsets to center the particle son screen int xOffset = (ofGetWidth() - w ) /2 ; int yOffset = (ofGetHeight() - h ) /2 ; numParticles= 0 ; r = ofRandom ( 45 , 255 ) ; g = ofRandom ( 45 , 255 ) ; b = ofRandom ( 45 , 255 ) ; ofVec3f origin = ofVec3f( ofGetWidth() /2 , ofGetHeight() /2 , 0 ) ; //Loop through all the rows for ( int x = 0 ; x < w ; x+=sampling ) { //Loop through all the columns for ( int y = 0 ; y < h ; y+=sampling ) { //Pixels are stored as unsigned char ( 0 <-> 255 ) as RGB //If our image had transparency it would be 4 for RGBA int index = ( y * w + x ) * 4 ; ofColor color ; if ( pixels[index+3] > 0 ) { color.r = r ; //pixels[index+0] ; //red pixel color.g = g ; //pixels[index+1] ; //blue pixel color.b = b ; //pixels[index+2] ; //green pixel ofVec3f spawnPoint = ofPoint ( x + xOffset , y + yOffset , ofRandom ( -50, 50 ) ) ; // spawnPoint.z = ; //origin.distance ( spawnPoint ) * 200.0f ; particles.push_back( Particle ( spawnPoint , color ) ) ; numParticles++ ; } } } ofSetFrameRate( 30 ) ; // numParticles = ( image.width * image.height ) / sampling ; //Set spring and sink values cursorMode = 0 ; forceRadius = 45 ; friction = 0.85 ; springFactor = 0.12 ; springEnabled = true ; //setup openGL ofSetFrameRate(30) ; ofBackground(0, 0, 0); //ofSetBackgroundAuto(false); ofSetVerticalSync(true); nImages = DIR.listDir("images/"); images = new ofImage[nImages]; //you can now iterate through the files as you like for(int i = 0; i < nImages; i++) { images[i].loadImage(DIR.getPath(i)); } fadeFbo.allocate( ofGetWidth() , ofGetHeight() ) ; fadeFbo.begin() ; ofClear(0, 0, 0, 1); fadeFbo.end() ; fadeAlpha = 2 ; }
void ofApplication::setup(){ // Renderer ofSetVerticalSync(true); ofEnableSmoothing(); ofEnableArbTex(); // setup animation parameters debugMode = false; // FLAGS bDrawUserOutline = true; bTrailUserOutline = true; bDrawHands = false; bTrailHands = false; bDrawPoi = false; bTrailPoi = false; // CIRCULAR GRADIENT + BACKGROUND bgBrightnessFade = 0.0f; bgSpotRadius = 1.0f; // TRAILS trailColorDecay = 0.975f; trailAlphaDecay = 0.98f; trailMinAlpha = 0.03f; trailVelocity = ofPoint(0.0f,80.0f); trailZoom = -0.1f; // USER OUTLINE userOutlineColorHSB = ofxNDHSBColor(0,0,255); userShapeScaleFactor = 1.1f; strobeLastDrawTime = 0; strobeIntervalMs = 0; // POI poiMaxScaleFactor = 0.1f; poiSpriteColorHSB = ofxNDHSBColor(0,255,255); // HANDS handsColorHSB = ofxNDHSBColor(0,0,200); ofFbo::Settings fboSettings; fboSettings.width = ofGetWidth(); fboSettings.height = ofGetHeight(); fboSettings.useDepth = false; fboSettings.useStencil = false; fboSettings.depthStencilAsTexture = false; fboSettings.numColorbuffers = 1; fboSettings.internalformat = GL_RGBA; mainFbo.allocate(fboSettings); mainFbo.begin(); mainFbo.activateAllDrawBuffers(); ofClear(0,0,0,0); mainFbo.end(); fboSettings.numColorbuffers = 2; fboSettings.width = ofGetWidth()*TRAIL_FBO_SCALE; fboSettings.height = ofGetHeight()*TRAIL_FBO_SCALE; fboSettings.internalformat = GL_RGBA32F_ARB; trailsFbo.allocate(fboSettings); trailsFbo.begin(); trailsFbo.activateAllDrawBuffers(); ofClear(0, 0, 0, 0); trailsFbo.end(); fboSettings.numColorbuffers = 1; fboSettings.width = 640; fboSettings.height = 480; fboSettings.internalformat = GL_RGBA; userFbo.allocate(fboSettings); userFbo.begin(); userFbo.activateAllDrawBuffers(); ofClear(0,0,0,0); userFbo.end(); trailsShader.load("shaders/vanilla.vert", "shaders/trails.frag"); userMaskShader.load("shaders/vanilla.vert", "shaders/userDepthMask.frag"); gaussianBlurShader.load("shaders/vanilla.vert", "shaders/gaussian.frag"); // midi setup midiIn.setVerbose(false); midiIn.openPort(s_inputMidiDeviceId); midiIn.addListener(this); // osc setup oscIn.setup(s_oscListenPort); // audio setup audioSensitivity = 1.0f; ofxAudioAnalyzer::Settings audioSettings; audioSettings.stereo = true; audioSettings.inputDeviceId = s_inputAudioDeviceId; audioSettings.bufferSize = 512; audioAnalyzer.setup(audioSettings); audioAnalyzer.setAttackInRegion(10, AA_FREQ_REGION_LOW); audioAnalyzer.setReleaseInRegion(250, AA_FREQ_REGION_LOW); audioAnalyzer.setAttackInRegion(5, AA_FREQ_REGION_MID); audioAnalyzer.setReleaseInRegion(120, AA_FREQ_REGION_MID); audioAnalyzer.setAttackInRegion(1, AA_FREQ_REGION_HIGH); audioAnalyzer.setReleaseInRegion(80, AA_FREQ_REGION_HIGH); // kinect setup #ifdef USE_KINECT kinectDriver.setup(); kinectAngle = 0; kinectOpenNI.setup(); kinectOpenNI.addImageGenerator(); kinectOpenNI.addDepthGenerator(); kinectOpenNI.setDepthColoring(COLORING_GREY); kinectOpenNI.setThreadSleep(15000); kinectOpenNI.setSafeThreading(false); kinectOpenNI.setRegister(true); kinectOpenNI.setMirror(true); #ifdef USE_USER_TRACKING // setup user generator kinectOpenNI.addUserGenerator(); kinectOpenNI.setMaxNumUsers(2); kinectOpenNI.setUseMaskPixelsAllUsers(true); kinectOpenNI.setUseMaskTextureAllUsers(true); kinectOpenNI.setUsePointCloudsAllUsers(false); kinectOpenNI.setSkeletonProfile(XN_SKEL_PROFILE_UPPER); kinectOpenNI.setUserSmoothing(0.4); #else // hands generator kinectOpenNI.addHandsGenerator(); kinectOpenNI.addAllHandFocusGestures(); kinectOpenNI.setMaxNumHands(2); kinectOpenNI.setMinTimeBetweenHands(50); #endif kinectOpenNI.start(); #ifdef USE_USER_TRACKING handPhysics = new ofxHandPhysicsManager(kinectOpenNI, true); #else handPhysics = new ofxHandPhysicsManager(kinectOpenNI, false); #endif handPhysics->restDistance = 0.0f; handPhysics->springCoef = 100.0f; handPhysics->smoothCoef = 0.5f; handPhysics->friction = 0.08f; handPhysics->gravity = ofVec2f(0,7000.0f); handPhysics->physicsEnabled = true; #endif }
//-------------------------------------------------------------- void currentColor::setup( float minutes, int n ) { imgWidth = 800; imgHeight = 50; fbo.allocate( imgWidth, imgHeight, GL_RGB ); colorPaletteImage.allocate( imgWidth, imgHeight, OF_IMAGE_COLOR ); nBars = n; //color timers startTime = ofGetSystemTime(); currentTime = startTime; lastTime = 0; colorTime = 0; cycleDuration = 1000 * 60 * minutes; colorDuration = cycleDuration / imgWidth; colorPosition = 0; transSpeed = 0; cycles = 1; colorPalette.resize( 10 ); gradientZone.resize( 9 ); zoneSize.resize( 10 ); //AWESOME/BORING colorPalette[ 0 ] = ofColor( 0, 171, 24 );//45, 255, 0 ); colorPalette[ 1 ] = ofColor( 74, 252, 141 );//0, 255, 255 ); colorPalette[ 2 ] = ofColor( 0, 246, 255 );//16, 0, 255 ); colorPalette[ 3 ] = ofColor( 72, 186, 228 );// 147, 0, 188 ); colorPalette[ 4 ] = ofColor( 0, 6, 253 );//250, 3, 255 ); colorPalette[ 5 ] = ofColor( 113, 0, 218 );//255, 0, 0 ); colorPalette[ 6 ] = ofColor( 169, 55, 201 );//255, 255, 255 ); colorPalette[ 7 ] = ofColor( 255, 43, 243 );//255, 255, 255 ); //colorPalette[ 7 ] = ofColor( 238, 0, 0 );//206, 255, 13 ); colorPalette[ 8 ] = ofColor(237, 237, 237 ); colorPalette[ 9 ] = ofColor( 0, 171, 24 );//237, 237, 237 ); zoneSize[ 0 ] = 0; zoneSize[ 1 ] = .21; zoneSize[ 2 ] = zoneSize[ 1 ] + .02; zoneSize[ 3 ] = zoneSize[ 2 ] + .04; zoneSize[ 4 ] = zoneSize[ 3 ] + .45; zoneSize[ 5 ] = zoneSize[ 4 ] + .09; zoneSize[ 6 ] = zoneSize[ 5 ] + .02; zoneSize[ 7 ] = zoneSize[ 6 ] + .12; zoneSize[ 8 ] = zoneSize[ 7 ] + .02; zoneSize[ 9 ] = zoneSize[ 8 ] + .03; //zoneSize[ 9 ] = 1.0 - zoneSize[ 8 ]; { fbo.begin(); ofClear(0); for ( int i = 0; i < gradientZone.size(); i ++ ) { // first triangle /*gradientZone[ i ].addVertex(ofVec3f( imgWidth * zoneSize[ i ], ofGetHeight()/2 - 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i ] ); gradientZone[ i ].addVertex(ofVec3f( imgWidth * zoneSize[ i + 1 ], ofGetHeight() / 2 - 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i + 1 ] ); gradientZone[ i ].addVertex(ofVec3f( imgWidth * zoneSize[ i + 1 ], ofGetHeight() / 2 + 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i + 1] ); // second triangle gradientZone[ i ].addVertex( ofVec3f( imgWidth * zoneSize[ i + 1 ], ofGetHeight() / 2 + 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i + 1 ] ); gradientZone[ i ].addVertex( ofVec3f( imgWidth * zoneSize[ i ], ofGetHeight() / 2 + 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i ] ); gradientZone[ i ].addVertex( ofVec3f( imgWidth * zoneSize[ i ], ofGetHeight()/2 - 200, 1 )); gradientZone[ i ].addColor( colorPalette[ i ] );*/ // first triangle gradientZone[ i ].addVertex(ofVec2f( imgWidth * zoneSize[ i ], 0 )); gradientZone[ i ].addColor( colorPalette[ i ] ); gradientZone[ i ].addVertex(ofVec2f( imgWidth * zoneSize[ i + 1 ], 0 )); gradientZone[ i ].addColor( colorPalette[ i + 1 ] ); gradientZone[ i ].addVertex(ofVec2f( imgWidth * zoneSize[ i + 1 ], 200 )); gradientZone[ i ].addColor( colorPalette[ i + 1] ); // second triangle gradientZone[ i ].addVertex( ofVec2f( imgWidth * zoneSize[ i + 1 ], 200 )); gradientZone[ i ].addColor( colorPalette[ i + 1 ] ); gradientZone[ i ].addVertex( ofVec2f( imgWidth * zoneSize[ i ], 200 )); gradientZone[ i ].addColor( colorPalette[ i ] ); gradientZone[ i ].addVertex( ofVec2f( imgWidth * zoneSize[ i ], 0 )); gradientZone[ i ].addColor( colorPalette[ i ] ); gradientZone[ i ].draw(); } fbo.end(); fbo.readToPixels( colorPalettePixels ); colorPaletteImage.setFromPixels( colorPalettePixels ); } currentColors.resize( nBars ); fromColors.resize( nBars ); toColors.resize( nBars ); lastColors.resize( nBars ); nextColors.resize( nBars ); for ( int i = 0; i < currentColors.size(); i ++ ) { lastColors[ i ] = ( int ) imgWidth / nBars * i; nextColors[ i ] = lastColors[ i ] + 1; currentColors[ i ] = colorPalettePixels.getColor( lastColors[ i ], 0 ); fromColors[ i ] = colorPalettePixels.getColor( lastColors[ i ], 0 ); toColors[ i ] = colorPalettePixels.getColor( nextColors[ i ], 0 ); } }
/* Call to render the next GL frame */ void Java_cc_openframeworks_OFAndroid_render( JNIEnv* env, jclass thiz ) { if(paused || surfaceDestroyed) return; if(!threadedTouchEvents){ mutex.lock(); queue<ofTouchEventArgs> events = touchEventArgsQueue; while(!touchEventArgsQueue.empty()) touchEventArgsQueue.pop(); mutex.unlock(); while(!events.empty()){ switch(events.front().type){ case ofTouchEventArgs::down: ofNotifyMousePressed(events.front().x,events.front().y,0); ofNotifyEvent(ofEvents().touchDown,events.front()); break; case ofTouchEventArgs::up: ofNotifyMouseReleased(events.front().x,events.front().y,0); ofNotifyEvent(ofEvents().touchUp,events.front()); break; case ofTouchEventArgs::move: ofNotifyMouseMoved(events.front().x,events.front().y); ofNotifyMouseDragged(events.front().x,events.front().y,0); ofNotifyEvent(ofEvents().touchMoved,events.front()); break; case ofTouchEventArgs::doubleTap: ofNotifyEvent(ofEvents().touchDoubleTap,events.front()); break; case ofTouchEventArgs::cancel: ofNotifyEvent(ofEvents().touchCancelled,events.front()); break; } events.pop(); } } ofNotifyUpdate(); if(ofGetGLProgrammableRenderer()){ ofGetGLProgrammableRenderer()->startRender(); } int width, height; width = sWindowWidth; height = sWindowHeight; height = height > 0 ? height : 1; // set viewport, clear the screen //glViewport( 0, 0, width, height ); ofViewport(0, 0, width, height, false); // used to be glViewport( 0, 0, width, height ); float * bgPtr = ofBgColorPtr(); bool bClearAuto = ofbClearBg(); if ( bClearAuto == true || ofGetFrameNum() < 3){ ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255); } if(bSetupScreen) ofSetupScreen(); ofNotifyDraw(); if(ofGetGLProgrammableRenderer()){ ofGetGLProgrammableRenderer()->finishRender(); } }
void ofxComposer::load(string _fileConfig){ if (_fileConfig != "default") configFile = _fileConfig; ofxXmlSettings XML; patches.clear(); if (XML.loadFile(_fileConfig)){ int totalPatchs = XML.getNumTags("surface"); // Load each surface present on the xml file // for(int i = 0; i < totalPatchs ; i++){ ofxPatch *nPatch = new ofxPatch(); bool loaded = nPatch->loadSettings(i, "config.xml"); if (loaded){ if (nPatch->getType() == "ofxGLEditor"){ ofLog(OF_LOG_NOTICE,"ofxComposer: ofxGLEditor loaded"); editor.setup("menlo.ttf"); editor.setCurrentEditor(1); editorFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight()); editorFbo.begin(); ofClear(0, 150); editorFbo.end(); nPatch->setTexture( editorFbo.getTextureReference(), 0); bGLEditor = true; } if (nPatch->getType() == "input"){ nPatch->setTexture( editorFbo.getTextureReference(), 0); } // Insert the new patch into the verctor // patches.push_back(nPatch); // Listen to close bottom on the titleBar // ofAddListener( patches[ patches.size()-1 ]->title->close , this, &ofxComposer::closePatch); } } // Load links between Patchs // for(int i = 0; i < totalPatchs ; i++){ if (XML.pushTag("surface", i)){ if (XML.pushTag("out")){ int totalLinks = XML.getNumTags("dot"); for(int j = 0; j < totalLinks ; j++){ if (XML.pushTag("dot",j)){ int toId = XML.getValue("to", 0); int toTex = XML.getValue("tex", 0); // If everything goes ok "i" will match the position of the vector // with the position on the XML, in the same place of the vector array // defined on the previus loop // connect( i , fromIDtoArrayPos( toId ), toTex); XML.popTag(); } } XML.popTag(); } XML.popTag(); } } } }
//-------------------------------------------------------------- void testApp::draw(){ mFbo.begin(); // to prevent uncleared video memory! ofSetColor(255, 255, 255, 0); ofClear(255, 255, 255, 0); ofSetColor(255, 255, 255, 255); ofPushMatrix();{ ofTranslate( pos ); ofSetRectMode( OF_RECTMODE_CENTER ); // for ( int i = 0; i < 4; i++ ) { // if ( i == 0 || i == 2 ) ofRotate( ofGetElapsedTimef() * 90 ); // else ofRotate( ofGetElapsedTimef() * 180 ); // ofRect( -50 * i, 50 * i, 50, 50 ); // } for ( int i = 0; i < 50; i++ ) { if ( i % 2 == 0 ) ofRotate( ofGetElapsedTimef() * 90 ); else ofRotate( ofGetElapsedTimef() * 180 ); ofRect( -10 * i, 40 * i, 50, 50 ); } ofSetRectMode( OF_RECTMODE_CORNER ); }ofPopMatrix(); mFbo.end(); mFbo2.begin(); // to prevent uncleared video memory! ofSetColor(255, 255, 255, 0); ofClear(255, 255, 255, 0); ofSetColor(255, 255, 255, 255); ofPushMatrix();{ ofTranslate( pos_2 ); ofSetRectMode( OF_RECTMODE_CENTER ); for ( int i = 0; i < 50; i++ ) { if ( i % 2 == 0 ) ofRotate( -ofGetElapsedTimef() * 45 ); else ofRotate( -ofGetElapsedTimef() * 135 ); ofRect( -20 * i, 30 * i, 50, 50 ); } ofSetRectMode( OF_RECTMODE_CORNER ); }ofPopMatrix(); mFbo2.end(); mFbo.draw(0,0); mFbo.draw(0,200); mFbo.draw(200,200); mFbo.draw(200,0); mFbo2.draw(0,0); mFbo2.draw(0,200); mFbo2.draw(200,200); mFbo2.draw(200,0); }
//-------------------------------------------------------------- void testApp::draw(){ //ofBackground( 255, 255, 255 ); //Set white background float time = ofGetElapsedTimef(); //1. Drawing to buffer fboTrails.begin(); //Draw semi-transparent white rectangle //to slightly clearing a buffer (depends on history value) ofEnableAlphaBlending(); //Enable transparency float alpha = (1-history) * 255; ofSetColor( 0, 0, 0, alpha ); ofFill(); ofClear(255, 255, 255, 0); //ofRect( 0, 0, ofGetWidth(), ofGetHeight() ); ofDisableAlphaBlending(); //Disable transparency //Draw the particles ofFill(); for (int i=0; i<p.size(); i++) { p[i].draw(); } fboTrails.end(); //Draw Background buffer fbo1.begin(); //ofBackgroundGradient( ofColor( 255 ), ofColor( 128 ) ); ofSetColor( 255, 255, 255 ); image.draw( 0, 0); fbo1.end(); //Draw Foreground greyscale buffer fbo2.begin(); //ofBackground( 0, 0, 0 ); imageGrey.draw(0,0); //ofBackground(255); //float ang = time * 30; ofPushMatrix(); //ofTranslate( 300, 384 ); //ofRotate( ang ); ofFill(); //ofSetColor( 255, 255, 255 ); ofSetColor(255); //ofTriangle( -200, -114, 200, -114, 0, 230 ); for(int i = 0; i<touches.size(); i++) { ofCircle(touches.at(i), TOUCH_RAD); } ofPopMatrix(); fbo2.end(); //Drawing to screen through the shader ofEnableAlphaBlending(); //NOTE: It is important to enable alpha blending for correct shader's working, //because shader performs masking by setting alpha-value of output color shader.begin(); shader.setUniform1f( "time", time ); //Pass float parameter "time" to shader //Pass mask to shader (fbo2) shader.setUniformTexture( "texture1", fbo2.getTextureReference(), 1 ); //Last parameter 1 is OpenGL texture identifier //Draw fbo image //ofSetColor( 255, 255, 255 ); fbo1.draw( 0, 0 ); shader.end(); //2. Draw buffer on the screen //ofSetColor( 255, 255, 255 ); fboTrails.draw( 0, 0 ); //GUI if ( debug ) { //Draw text debugDraw(); } }
void SpriteSource::draw(){ ofClear(0, 0, 0, 0); sheet.draw(getWidth(), getHeight()); }
void CloudsVisualSystemPaintBrush::drawPaint(){ canvasDst.begin(); ofClear(0,0); ofPushStyle(); ofDisableDepthTest(); ofEnableAlphaBlending(); // ofSetColor(255, 255); ofSetColor(255, .999999999*255); canvasSrc.draw(0, 0); ofSetColor(255, 255); //MA: replaced ofGetMouseX() with GetCloudsInputX() ofCircle(GetCloudsInputX(), GetCloudsInputY(), 20); // ofSetColor(255, 255, 255, fadeAmount*255); // ofEnableBlendMode(OF_BLENDMODE_SUBTRACT); // ofRect(0,0,canvasDst.getWidth(),canvasDst.getHeight()); ofDisableAlphaBlending(); ofEnableAlphaBlending(); ofSetColor(255); for(int i = particles.size()-1; i >= 0 ; i--){ particles[i].addNoise(ofGetElapsedTimef(), particlesTurbulence); particles[i].update(); if (particles[i].getVel().length() < 1.0 ){ particles.erase(particles.begin()+i); } else { particles[i].draw(); particles[i].trail.draw(); } } vector<int> toRemove; for (map<int, Brush *>::iterator it = brushes.begin(); it != brushes.end(); it++) { Brush * brush = it->second; if (brush->bDown) { brush->draw(); } else { toRemove.push_back(it->first); } } ofPopStyle(); canvasDst.end(); swap(canvasSrc, canvasDst); while(particles.size() > 500) { particles.erase(particles.begin()); } // get rid of any idle brushes for (int i = 0; i < toRemove.size(); i++) { delete brushes[toRemove[i]]; brushes.erase(toRemove[i]); } }
//-------------------------------------------------------------- void ofApp::setup(){ // SETUP // imageDir, imageSavePath = location of images, path to save the final grid image // nx, ny = size of the grid (make sure there are at least nx*ny images in imageDir!) // w, h = size of the image thumbnails // perplexity, theta (for t-SNE, see 'example' for explanation of these) // -------------- SET FILE I/O --------------- string imageDir = "../../../../../../../../../Volumes/BenSnell/torsos-7k/photos-jpg"; // source directory string folderName = "torsos_7k_all"; // destination directory // ------------------------------------------- nx = 87; ny = 87; w = 340; h = 510; perplexity = 75; theta = 0.001; ///////////////////////////////////////////////////////////////////// // CCV activations -> t-SNE embedding -> grid assignments // get images recursively from directory ofLog() << "Gathering images..."; ofDirectory dir = ofDirectory(imageDir); scan_dir_imgs(dir); if (imageFiles.size() < nx * ny) { ofLog(OF_LOG_ERROR, "There are less images in the directory than the grid size requested (nx*ny="+ofToString((nx*ny))+"). Exiting to save you trouble..."); // ofExit(); // not enough images to fill the grid, so quitting } // load all the images // for(int i=0; i<nx*ny; i++) { // if (i % 20 == 0) ofLog() << " - loading image "<<i<<" / "<<nx*ny<<" ("<<dir.size()<<" in dir)"; // images.push_back(ofImage()); // images.back().load(imageFiles[i]); //// images.back().resize(w, h); // ADDED -- DOES THIS WORK? // } for(int i=0; i<imageFiles.size(); i++) { if (i % 20 == 0) ofLog() << " - loading image "<<i<<" / "<<imageFiles.size()<<" ("<<dir.size()<<" in dir)"; images.push_back(ofImage()); images.back().load(imageFiles[i]); // images.back().resize(w, h); // ADDED -- DOES THIS WORK? } // resize images to w x h for (int i=0; i<images.size(); i++) { if (images[i].getWidth() > images[i].getHeight()) { images[i].crop((images[i].getWidth()-images[i].getHeight()) * 0.5, 0, images[i].getHeight(), images[i].getHeight()); } else if (images[i].getHeight() > images[i].getWidth()) { images[i].crop(0, (images[i].getHeight()-images[i].getWidth()) * 0.5, images[i].getWidth(), images[i].getWidth()); } images[i].resize(w, h); } // setup ofxCcv ccv.setup("image-net-2012.sqlite3"); // encode all of the images with ofxCcv ofLog() << "Encoding images..."; for (int i=0; i<images.size(); i++) { if (i % 20 == 0) ofLog() << " - encoding image "<<i<<" / "<<images.size(); vector<float> encoding = ccv.encode(images[i], ccv.numLayers()-1); encodings.push_back(encoding); } // run t-SNE and load image points to imagePoints ofLog() << "Run t-SNE on images"; tsneVecs = tsne.run(encodings, 2, perplexity, theta, true); // tsneVecs contains {x, y} for each image in images // save tsne ofFile tsneFile; tsneFile.open(folderName + "/" + "tsne_only_metadata.csv", ofFile::WriteOnly); tsneFile << "image_name,tsne_x,tsne_y"; for (int i = 0; i < images.size(); i++) { tsneFile << "\n"; tsneFile << imageFiles[i].getFileName() << ","; tsneFile << ofToString(tsneVecs[i][0]) << ","; tsneFile << ofToString(tsneVecs[i][1]); } tsneFile.close(); ofExit(); // TEMP!!! // solve assignment grid vector<ofVec2f> tsnePoints; // convert vector<double> to ofVec2f for (auto t : tsneVecs) tsnePoints.push_back(ofVec2f(t[0], t[1])); vector<ofVec2f> gridPoints = makeGrid(nx, ny); solvedGrid = solver.match(tsnePoints, gridPoints, false); // export data to csv containing names and positions of images bool bExport = true; if (bExport) { int nImages = images.size(); //nx * ny; ofFile file; file.open(folderName + "/" + "tsne_metadata.csv", ofFile::WriteOnly); file << "image_name,grid_row,grid_column,grid_x_norm,grid_y_norm,tsne_x,tsne_y"; for (int i = 0; i < nImages; i++) { file << "\n"; file << imageFiles[i].getFileName() << ","; file << ofToString(solvedGrid[i].x * (nx-1)) << ","; file << ofToString(solvedGrid[i].y * (ny-1)) << ","; file << ofToString(solvedGrid[i].x) << ","; file << ofToString(solvedGrid[i].y) << ","; file << ofToString(tsneVecs[i][0]) << ","; file << ofToString(tsneVecs[i][1]); } file.close(); } // save image grid bool bSaveGrid = true; if (bSaveGrid) { string imageGridName = "tsne_grid.png"; ofFbo fbo; fbo.allocate(nx * w, ny * h); fbo.begin(); ofClear(0, 0); ofBackground(0); for (int i=0; i<solvedGrid.size(); i++) { float x = (fbo.getWidth() - w) * solvedGrid[i].x; float y = (fbo.getHeight() - h) * solvedGrid[i].y; images[i].draw(x, y, w, h); } fbo.end(); ofImage img; fbo.readToPixels(img); img.save(folderName + "/" + imageGridName); } // save image clusters bool bSaveClusters = true; float imgScale = 0.5; if (bSaveClusters) { string imageClustersName = "tsne_clusters.png"; ofFbo fbo; fbo.allocate(nx * w, ny * h); fbo.begin(); ofClear(0, 0); ofBackground(255); for (int i=0; i<tsneVecs.size(); i++) { float x = (fbo.getWidth() - w) * tsneVecs[i][0]; float y = (fbo.getHeight() - h) * tsneVecs[i][1]; ofSetColor(255, 180); images[i].draw(x, y, w * imgScale, h * imgScale); ofSetColor(0); ofDrawBitmapString(imageFiles[i].getFileName(), x, y + h * imgScale); } fbo.end(); ofImage img; fbo.readToPixels(img); img.save(folderName + "/" + imageClustersName); } // setup gui gui.setup(); gui.add(scale.set("scale", 1.0, 0.0, 1.0)); }
//-------------------------------------------------------------- void ofApp::update(){ pointLight.setPosition((ofGetWidth()*.8)+ cos(ofGetElapsedTimef()*.5)*(ofGetWidth()*.8), ofGetHeight()/2, 500); pointLight2.setPosition((ofGetWidth()*.8)+ cos(ofGetElapsedTimef()*.5)*(ofGetWidth()*.8), -ofGetHeight()/2, -500); heart_vertices[100].set(1400,1400,1400); int cnt =0; for(int i=0; i < 3;i++){ for(int j=0; j < heart[i].getNumVertices(); j+=10){ for(int k=0; k < nearest[cnt].size();k++){ heart[i].setVertex(nearest[cnt][k],heart_[i].getVertex(nearest[cnt][k])*(ofNoise(ofGetFrameNum()/100.0f,j)*fftSmoothed[0]*0.4+1)); } cnt++; } } float * val = ofSoundGetSpectrum(nBandsToGet); // request 128 values for fft for (int i = 0;i < nBandsToGet; i++){ // let the smoothed calue sink to zero: fftSmoothed[i] *= 0.96f; // take the max, either the smoothed or the incoming: if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i]; } if(!beat.isPlaying())beat.play(); myFbo.begin(); ofClear(0,0,0,255); cam.begin(); ofPushMatrix(); ofTranslate(0, 0,-400); ofEnableAlphaBlending(); for(int key=0; key<IMG_SIZE; key++){ float n = ofNoise(key,ofGetFrameNum()/80.0f); if(n>0.9) { ofSetColor(255,255,255,255); images[key].draw(-ofGetWidth()/2, -ofGetHeight()/2, ofGetWidth(), ofGetHeight()); cout<<key<<endl; } } ofDisableAlphaBlending(); //mizukusa.draw(ofPoint(-ofGetWidth()/2, -ofGetHeight()/2,1500) ,ofGetWidth(), ofGetHeight()); ofPopMatrix(); ofEnableDepthTest(); ofEnableLighting(); pointLight.enable(); pointLight2.enable(); ofPushMatrix(); { ofPushMatrix(); { ofScale(0.3,0.3); ofTranslate(ofGetWidth()/2*0.8,ofGetHeight()/2*0.8); ofRotateY(ofGetFrameNum()/3.0f); for(int i=0; i < 3; i++){ //heart[i].draw(); } }ofPopMatrix(); material.end(); ofScale(2.6,2.6); ofRotateY(ofGetFrameNum()/3.0f); ofRotateX(ofGetFrameNum()/1.8f); material.begin(); for(int i=0; i < 3; i++){ heart[i].draw(); } } ofPopMatrix(); ofDisableLighting(); cam.end(); myFbo.end(); for(int i=0; i < 6; i++){ noises[i] = ofNoise(i+1,ofGetFrameNum()/100.0f); } for(int key=0; key<6; key++){ if(noises[key]>0.9 && key == 0) myGlitch.setFx(OFXPOSTGLITCH_GLOW , true); else if(key==0) myGlitch.setFx(OFXPOSTGLITCH_GLOW , false); if(noises[key]>0.8 && key == 1) myGlitch.setFx(OFXPOSTGLITCH_CUTSLIDER , true); else if(key==1) myGlitch.setFx(OFXPOSTGLITCH_CUTSLIDER , false); if(noises[key]>0.8 && key == 2) myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE , true); else if(key==2) myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE , false); if(noises[key]>0.8 && key == 3) myGlitch.setFx(OFXPOSTGLITCH_SLITSCAN , true); else if(key==3) myGlitch.setFx(OFXPOSTGLITCH_SLITSCAN , false); if(noises[key]>0.8 && key == 4) myGlitch.setFx(OFXPOSTGLITCH_NOISE , true); else if(key==4) myGlitch.setFx(OFXPOSTGLITCH_NOISE , false); if(noises[key]>0.8 && key == 5) myGlitch.setFx(OFXPOSTGLITCH_TWIST , true); else if(key==5) myGlitch.setFx(OFXPOSTGLITCH_TWIST , false); } }
void testApp::takePicture(){ unsigned char * greyPixels = bmp.getPixels(); ofPixels pixels; pixels.allocate(bmp.getWidth(), bmp.getHeight(), 3); imageSmall.readToPixels(pixels); ofPixels channel = pixels.getChannel(0); for (int i = 0; i < channel.size(); i++) { greyPixels[i] = channel[i]; } bmp.update(); string timestamp = ofToString(ofGetUnixTime()); string filename = timestamp + ".bmp"; bmp.saveImage(filename); /*ofPixels pixelsBig; pixelsBig.allocate(image.getWidth(), image.getHeight(), 3); image.readToPixels(pixelsBig); ofPixels channelBig = pixelsBig.getChannel(0); uint8_t * printData = new uint8_t [(int) image.getWidth()* (int)image.getHeight()]; uint8_t currByte; for (int i = 0; i < channelBig.size(); i++) { currByte <<= 1; currByte |= ((int)channelBig[i] > 100) ? 0 : 1; if(i%8 == 7){ printData[i] = currByte; } }*/ //printBitmap(image.getWidth(), image.getHeight(), printData); string script = ofFilePath::getEnclosingDirectory(ofFilePath::getCurrentExePath(), false) + "../Resources/Bits2DNA.pl"; string command = "perl " + script + " \"" + ofToDataPath(filename) + "\" \"" + ofToDataPath(filename)+".dna" + "\""; system(command.c_str()); ofBuffer buffer = ofBufferFromFile(filename + ".dna" ); vector<int> data; while (!buffer.isLastLine()) { string line = ofToUpper(buffer.getNextLine()); for (int i = 0; i < line.size(); i++) { char letter = line[i]; switch (letter) { case 'A': data.push_back(0); break; case 'G': data.push_back(1); break; case 'T': data.push_back(2); break; case 'C': data.push_back(3); break; } } } printImage.allocate(384, 50 + 384 + (int) (data.size() / (384 / 4)) * 4); //printImage.allocate(100, 20 ); printImage.begin(); ofClear(255,255,255); ofSetColor(0, 0, 0, 255); ofDrawBitmapString("ART HACK DAY STOCKHOLM 2013", 0, 14); ofDrawBitmapString(timestamp + ".BMP.DNA", 0, 30); ofSetColor(255, 255, 255, 255); image.draw(20, 60, 344,344); //image.draw(0, 0, 344,344); int row = 0; int col = 0; int maxCols = 384/4; ofPushMatrix(); ofTranslate(0, 50 + 384); for (int i = 0; i < data.size(); i++) { ofSetColor(255,255,255); bases[data[i]].draw(col*4, row*4, 4,4); col++; if(col >= maxCols){ col = 0; row++; } } ofPopMatrix(); printImage.end(); ofImage printBmp; printBmp.allocate(printImage.getWidth(), printImage.getHeight(), OF_IMAGE_GRAYSCALE); unsigned char * printPixels = printBmp.getPixels(); ofPixels printFBOpixels; printFBOpixels.allocate(printImage.getWidth(), printImage.getHeight(), 3); printImage.readToPixels(printFBOpixels); ofPixels printChannel = printFBOpixels.getChannel(0); //uint8_t * printData = new uint8_t [(int) printImage.getWidth()* (int)printImage.getHeight()/8]; //uint8_t currByte; for (int i = 0; i < printChannel.size(); i++) { printPixels[i] = ((int)printChannel[i] > 100) ? 255 : 0; //currByte <<= 1; //currByte |= ((int)channel[i] > 100) ? 0 : 1; //if(i%8 == 7){ //printData[i] = currByte; //} } printBmp.update(); int width = printImage.getWidth(); int height = printImage.getHeight(); //zzprintBitmap(width, height, printData); //delete printData; printBmp.saveImage(filename+".print.bmp"); }
ofxFlocking& ofxFlocking::allocate(int _width, int _height, int _nBoids){ width = _width; height = _height; resolution = (int) sqrt(_nBoids); nBoids = resolution * resolution; cout << "- flocking system, resolution " << resolution << " boids n: " << nBoids << endl; string fragmentVelUpdateShader = "#version 120\n \ #extension GL_ARB_texture_rectangle : enable \n \ \ uniform sampler2DRect posData;\ uniform sampler2DRect prevVelData;\ \ uniform sampler2DRect normalTex;\ uniform sampler2DRect obstacleTex;\ uniform sampler2DRect foodTex;\ \ uniform vec2 screen;\ uniform int resolution;\ \ uniform float timestep;\ uniform float minDist;\ uniform float maxDist;\ uniform float maxSpeed;\ uniform float maxForce;\ \ uniform float separation;\ uniform float alineation;\ uniform float cohesion;\ \ uniform float borders;\ \ vec2 offset[9];\ \ vec2 limit(vec2 vector, float max){\ float lengthSquared = dot(vector,vector);\ if( lengthSquared > max*max && lengthSquared > 0.0 ) {\ float ratio = max/sqrt(lengthSquared);\ vector.x *= ratio;\ vector.y *= ratio;\ }\ return vector;\ }\ \ vec2 avoid(vec2 pos, vec2 target, bool weight){\ vec2 steer = target - pos;\ if(weight) steer *= 1.0/sqrt(distance(pos,target));\ return steer;\ }\ \ void main(void){\ vec2 st = gl_TexCoord[0].st;\ \ float life = texture2DRect( prevVelData, st ).z;\ \ vec2 pos = texture2DRect( posData, st).xy;\ vec2 vel = texture2DRect( prevVelData, st ).xy;\ vec2 acc = vec2(0.0,0.0);\ \ vec2 texSt = pos * screen;\ \ float foodPresent = texture2DRect(foodTex, texSt).g;\ \ if ( foodPresent > 0.0 )\ life += foodPresent * 0.05;\ else \ life -= 0.1;\ \ if (life > 0.0){\ offset[0] = vec2(-1.0, -1.0);\ offset[1] = vec2(0.0, -1.0);\ offset[2] = vec2(1.0, -1.0);\ \ offset[3] = vec2(-1.0, 0.0);\ offset[4] = vec2(0.0, 0.0);\ offset[5] = vec2(1.0, 0.0);\ \ offset[6] = vec2(-1.0, 1.0);\ offset[7] = vec2(0.0, 1.0);\ offset[8] = vec2(1.0, 1.0);\ \ float obst = texture2DRect( obstacleTex , texSt).b;\ if (obst > 0.0){\ \ float lessDense = 2.0;\ int lessDenseOffset = 4;\ \ float moreFood = 0.0;\ int moreFoodOffset = 4;\ \ for (int i = 0; i < 9; i++){\ if (i != 4){\ float nearby = texture2DRect(obstacleTex , texSt + offset[i] ).b;\ if ( nearby < lessDense){\ lessDense = nearby;\ lessDenseOffset = i;\ }\ \ float foodAmount = texture2DRect(foodTex, texSt + offset[i] ).g;\ if ( foodAmount > moreFood){\ foodAmount = foodAmount;\ moreFoodOffset = i;\ }\ }\ }\ \ acc += (offset[lessDenseOffset] + offset[moreFoodOffset]) * 0.5;\ \ } else {\ vec2 sep = vec2(0.0,0.0);\ vec2 ali = vec2(0.0,0.0);\ vec2 coh = vec2(0.0,0.0);\ \ float near = 0.0;\ float toNear = 0.0;\ \ for (int x = 0; x < resolution; x++){\ for ( int y = 0; y < resolution; y++){\ \ if(st != vec2(x,y)){\ float tLife = texture2DRect( prevVelData, vec2(x,y) ).z;\ \ if (tLife > 0.0){\ vec2 tPos = texture2DRect( posData, vec2(x,y) ).xy;\ vec2 tVel = texture2DRect( prevVelData, vec2(x,y) ).xy;\ \ vec2 diff = pos - tPos;\ float d = length(diff);\ \ if ( d < maxDist){\ ali += tVel;\ coh += tPos;\ near++;\ \ if ( d < minDist){\ sep += (normalize(diff) / d);\ toNear++;\ }\ }\ }\ }\ }\ }\ \ if (toNear > 0.0){\ sep /= toNear;\ sep = normalize(sep);\ sep *= maxSpeed;\ sep -= vel;\ sep = limit(sep,maxForce);\ }\ \ if (near > 0.0){\ ali /= near;\ ali = normalize(ali);\ ali *= maxSpeed;\ ali -= vel;\ ali = limit(ali,maxForce);\ \ coh /= near;\ coh -= pos;\ coh = normalize(coh);\ coh *= maxSpeed;\ coh -= vel;\ coh = limit(coh,maxForce);\ }\ \ acc += sep * separation;\ acc += ali * alineation;\ acc += coh * cohesion;\ \ acc += avoid(pos,vec2(pos.x,1.0),true) * borders;\ acc += avoid(pos,vec2(pos.x,0.0),true) * borders;\ acc += avoid(pos,vec2(1.0,pos.y),true) * borders;\ acc += avoid(pos,vec2(0.0,pos.y),true) * borders;\ }\ \ vel += acc;\ vel = limit(vel,maxSpeed);\ \ vec2 nextPos = pos;\ nextPos += vel * timestep;\ \ if ( nextPos.x < 0.0)\ vel.x = 0.5 * abs(vel.x);\ \ if ( nextPos.x > 1.0)\ vel.x = -0.5 * abs(vel.x);\ \ if (nextPos.y < 0.0)\ vel.y = 0.5 * abs(vel.y);\ \ if ( nextPos.y > 1.0)\ vel.y = -0.5 * abs(vel.y);\ } \ \ life = clamp(life,0.0,1.0);\ \ gl_FragColor.rgb = vec3(vel.x,vel.y,life);\ gl_FragColor.a = 1.0;\ }"; velUpdateShader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentVelUpdateShader); velUpdateShader.linkProgram(); //velUpdateShader.load("","shaders/flockingVelUpdate.frag"); string fragmentPosUpdateShader = "#version 120\n \ #extension GL_ARB_texture_rectangle : enable \n \ \ uniform sampler2DRect prevPosData;\ uniform sampler2DRect velData;\ \ uniform float timestep;\ \ void main(void){\ vec2 st = gl_TexCoord[0].st;\ \ vec2 pos = texture2DRect( prevPosData, st ).xy;\ vec2 vel = texture2DRect( velData, st ).xy;\ \ float life = texture2DRect( velData, st ).z;\ \ if (life > 0.0)\ pos += vel * timestep;\ \ gl_FragColor.rgba = vec4(pos.x,pos.y,life,1.0);\ }"; posUpdateShader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentPosUpdateShader); posUpdateShader.linkProgram(); //posUpdateShader.load("","shaders/flockingPosUpdate.frag"); renderShader.setGeometryInputType(GL_POINTS); renderShader.setGeometryOutputType(GL_TRIANGLE_STRIP); renderShader.setGeometryOutputCount(6); string fragmentRenderShader = "#version 120\n \ #extension GL_ARB_texture_rectangle : enable \n \ \ uniform sampler2DRect sparkTex;\ void main() {\ vec2 st = gl_TexCoord[0].st;\ gl_FragColor = texture2DRect(sparkTex, st);\ }"; renderShader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentRenderShader); string vertexRenderShader = "#version 120 \n \ #extension GL_EXT_gpu_shader4 : enable \n \ #extension GL_ARB_texture_rectangle : enable \n \ \ uniform sampler2DRect posTex;\ uniform vec2 screen;\ uniform int resolution;\ \ void main() {\ vec4 pos = gl_Vertex;\ \ pos.x *= screen.x;\ pos.y *= screen.y;\ pos.z = clamp(pos.z,0.0,1.0);\ \ gl_Position = pos;\ gl_FrontColor = gl_Color;\ }"; renderShader.setupShaderFromSource(GL_VERTEX_SHADER, vertexRenderShader); string geometryRenderShader = "#version 120 \n \ #extension GL_EXT_geometry_shader4 : enable \n \ #extension GL_EXT_gpu_shader4 : enable \n \ \ uniform float size;\ uniform float imgWidth, imgHeight; \ \ void main(void){\ for(int i = 0; i < gl_VerticesIn; i++){\ float life = size * gl_PositionIn[i].z;\ \ gl_Position = gl_ModelViewProjectionMatrix * ( gl_PositionIn[i] + vec4(-life,-life,0.0,0.0));\ gl_TexCoord[0].x = 0.0; \ gl_TexCoord[0].y = 0.0; \ EmitVertex();\ \ gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + vec4(life,-life,0.0,0.0));\ gl_TexCoord[0].x = imgWidth;\ gl_TexCoord[0].y = 0.0;\ EmitVertex();\ \ gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + vec4(life,life,0.0,0.0));\ gl_TexCoord[0].x = imgWidth; \ gl_TexCoord[0].y = imgHeight; \ EmitVertex();\ EndPrimitive();\ \ gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + vec4(-life,-life,0.0,0.0));\ gl_TexCoord[0].x = 0.0; \ gl_TexCoord[0].y = 0.0; \ EmitVertex();\ \ gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + vec4(-life,life,0.0,0.0));\ gl_TexCoord[0].x = 0.0; \ gl_TexCoord[0].y = imgHeight; \ EmitVertex();\ \ gl_Position = gl_ModelViewProjectionMatrix * (gl_PositionIn[i] + vec4(life,life,0.0,0.0));\ gl_TexCoord[0].x = imgWidth; \ gl_TexCoord[0].y = imgHeight; \ EmitVertex();\ EndPrimitive();\ }\ }"; renderShader.setupShaderFromSource(GL_GEOMETRY_SHADER, geometryRenderShader); renderShader.linkProgram(); //renderShader.load("shaders/flockingRender.vert","shaders/flockingRender.frag","shaders/flockingRender.geom"); sparkImage.loadImage("textures/life/spark.png"); imageWidth = sparkImage.getWidth(); imageHeight = sparkImage.getHeight(); // 1. Process birth and death float * pos = new float[nBoids*3]; float offset = 1.0/resolution; for (int x = 0; x < resolution; x++){ for (int y = 0; y < resolution; y++){ int i = resolution * y + x; pos[i*3 + 0] = ofRandom(1.0); //x*offset; pos[i*3 + 1] = ofRandom(1.0); //y*offset; pos[i*3 + 2] = 1.0; //pos[i*4 + 3] = 1.0; } } ofTexture posTex; posTex.allocate(resolution, resolution, GL_RGB16F); posTex.loadData(pos, resolution, resolution, GL_RGB); delete(pos); float * vel = new float[nBoids*3]; for (int i = 0; i < nBoids; i++){ vel[i*3 + 0] = ofRandom(-1,1); vel[i*3 + 1] = ofRandom(-1,1); vel[i*3 + 2] = 1.0; //vel[i*4 + 3] = 1.0; } ofTexture velTex; velTex.allocate(resolution, resolution, GL_RGB16F); velTex.loadData(vel, resolution, resolution, GL_RGB); delete(vel); pixels.allocate(resolution,resolution, 4); particles = new ofPoint[nBoids]; for (int i = 0; i < nBoids; i++){ particles[i].set(0.0,0.0,0.0); } for(int i = 0; i < 2; i++){ posFbo[i].allocate(resolution,resolution,GL_RGB16F); posFbo[i].begin(); ofClear(0); posTex.draw(0,0); posFbo[i].end(); velFbo[i].allocate(resolution,resolution,GL_RGB16F); velFbo[i].begin(); ofClear(0); velTex.draw(0,0); velFbo[i].end(); } renderFbo.allocate(width,height,GL_RGBA); renderFbo.begin(); ofClear(0); renderFbo.end(); return * this; }
//-------------------------------------------------------------- void testApp::draw(){ ofClear(255, 255, 255, 0); ofSetColor(255, 255, 255,255); //Draw Flying Videos drawBoids(); //Clear Background ofClear(255, 255, 255, 0); //Tranparent Background) ofBackground(255, 255, 255, 0); //Tranparent Background //Text ofFill(); if (cvImgDisp) { ofSetColor(255, 0, 0); // RED FOR DEBUG }else{ ofSetColor(255, 255, 255,255); // White for display color } drawText(); ofSetColor(210, 229, 247, 255); //BACKGROUND FOR FLYERS ofRect(0,0, ofGetWidth(), ofGetHeight()); //bgImg.draw(0,0); // TEXTURE FOR FLYERS // OR VIDEO TEXTURE //bgVideo.play(); /* bgVideo.draw(0,0,ofGetWidth(), ofGetHeight()); */ // MULTIPLE SEQUENCE /* if(endRecordSequence == true){ bgVideoEndRec.play(); bgVideoEndRec.draw(0,0,ofGetWidth(), ofGetHeight()); bgVideo.stop(); }else { bgVideo.play(); bgVideo.draw(0,0,ofGetWidth(), ofGetHeight()); bgVideoEndRec.stop(); } */ if(posBgImg >= 0 && endRecordSequence){ posBgImg = 0; }else{ posBgImg = videoPos*1-960; } bgImg.draw(posBgImg,0 , 1920, ofGetHeight()); // TEXTURE FOR FLYERS ofSetColor(255, 255, 255,255); ////COVER TEXT //Cutout ofSetColor(255, 255, 255,255); //ofSetColor can change the tint of an image, this resets is cutoutTex.draw((0-videoPos*1.5)+200,(ofGetHeight()/2)-(camHeightScale/2) , camWidthScale, camHeightScale); // correct proportions //Show the 'End Record Sequence' if (endRecordSequence == true) { string goodbye = "Tu voles maintenant sur la Carte Blanche!"; ofPushStyle(); //ofSetColor(28, 20, 255); ofPushMatrix(); ofTranslate(900, (ofGetHeight()/2)+350); ofRotateZ(-90); ofSetColor(255, 255, 255); shimmer.drawString(goodbye, 0, 0); ofSetColor(28, 20, 255); shimmer.drawString(goodbye, 1, 1); ofPopMatrix(); ofPopStyle(); } //Tell people that the buffer is full if that is true if (bufferFull && !endRecordSequence) { string full = "La carte est pleine! L'enregistrement reprendra lors du prochain spectacles"; ofPushStyle(); ofSetColor(28, 20, 255); ofPushMatrix(); ofTranslate(900, (ofGetHeight()/2)+480); ofRotateZ(-90); shimmer.drawString(full, 0, 0); ofPopMatrix(); ofPopStyle(); } //Progress bar for recording //ofSetColor(255-(100-index)*2,0,0,255); //ofSetColor(0, 229, 247, 255); if(endRecordSequence == false){ ofSetColor(255, 0, 0, 50); ofRect(800,(ofGetHeight()/2), 15, 200); ofRect(800,(ofGetHeight()/2), 15, -200); ofSetColor(255, 0, 0, 255); /* ofRect(800,(ofGetHeight()/2), 15, (100-index)*2); ofRect(800,(ofGetHeight()/2), 15, -(100-index)*2); */ //videoProgessBar = videoProgressBar - videoPos; /* if(videoProgressBar == 0){ endRecordSequence =true; }else { endRecordSequence=false; } */ ofRect(800,(ofGetHeight()/2), 15, (100-videoPos/4)*2); ofRect(800,(ofGetHeight()/2), 15, -(100-videoPos/4)*2); // test circle progress // ofCircle((ofGetHeight()/2),(150+index)*2,20); ofSetColor(255, 255, 255, 255); //posBgImg = -1280; /* progressBar.draw(800,(ofGetHeight()/2), 20, 200); progressBar.draw(800,(ofGetHeight()/2), 20, -200); */ /* progressBar.draw(800,(ofGetHeight()/2), 20, (100-index)*2); progressBar.draw(800,(ofGetHeight()/2), 20, -(100-index)*2); */ ofSetColor(210, 229, 247, 120); ofNoFill(); ofRect(794,(ofGetHeight()/2)-205,25,410); }else{ ofRect(800,0, 15, 0); ofRect(800,0, 15, 0); progressBar.draw(800,0, 15, 0); progressBar.draw(800,0, 15, 0); } /* OLD MECANISM FOR THE PROGRESS BAR ofSetColor(255-(100-index)*2,0,0,255); ofRect(800,(ofGetHeight()/2), 20, (100-index)*2); ofRect(800,(ofGetHeight()/2), 20, -(100-index)*2); */ //Debug Functions // shimmer.drawString(ofToString(index), ofGetWidth()-50, ofGetHeight()-50); ofSetColor(0,0,0, 120); //shimmer.drawString(ofToString(showState), ofGetWidth()-50, ofGetHeight()-50); //shimmer.drawString(ofToString(posBgImg), ofGetWidth()-150, ofGetHeight()-100); //shimmer.drawString(ofToString(lowBlob), ofGetWidth()-300, ofGetHeight()-100); //shimmer.drawString(ofToString(highBlob), ofGetWidth()-300, ofGetHeight()-150); /* shimmer.drawString(ofToString(showBoidsHead-showBoidsTail), ofGetWidth()-180, 50); shimmer.drawString("de" , ofGetWidth()-120, 50); shimmer.drawString(ofToString(bufferSize), ofGetWidth()-70, 50); shimmer.drawString(ofToString(posBgImg), ofGetWidth()-200, 100); */ //shimmer.drawString(ofToString(videoPos), ofGetWidth()-70, 50); //shimmer.drawString(ofToString(highBlob), ofGetWidth()-200, 100); if (cvImgDisp) { cvImages(); } //get the last playIndex before the program loops back lastPlayIndex = playIndex; }
//-------------------------------------------------------------- void testApp::setup() { Tweenzor::init( ) ; ofSetLogLevel(OF_LOG_WARNING); bDrawOpenNI = false; //#ifndef USE_ONI_MOVIE openNIDevice.setup(); openNIDevice.addImageGenerator(); openNIDevice.addDepthGenerator(); openNIDevice.setRegister(true); openNIDevice.setMirror(false); openNIDevice.addUserGenerator(); openNIDevice.setMaxNumUsers(4); openNIDevice.start(); // set properties for all user masks and point clouds //openNIDevice.setUseMaskPixelsAllUsers(true); // if you just want pixels, use this set to true openNIDevice.setUseMaskTextureAllUsers(true); // this turns on mask pixels internally AND creates mask textures efficiently openNIDevice.setUsePointCloudsAllUsers(false); // openNIDevice.setPointCloudDrawSizeAllUsers(2); // size of each 'point' in the point cloud // openNIDevice.setPointCloudResolutionAllUsers(2); // resolution of the mesh created for the point cloud eg., this will use every second depth pixel // you can alternatively create a 'base' user class // ofxOpenNIUser user; // user.setUseMaskTexture(true); // user.setUsePointCloud(true); // user.setPointCloudDrawSize(2); // user.setPointCloudResolution(2); // openNIDevice.setBaseUserClass(user); //#endif /* openNIPlayer.setup(); openNIPlayer.addImageGenerator(); openNIPlayer.addDepthGenerator(); openNIPlayer.setRegister(true); openNIPlayer.setMirror(false); openNIPlayer.addUserGenerator(); openNIPlayer.setMaxNumUsers(2); openNIPlayer.start(); openNIPlayer.setUseMaskTextureAllUsers(true); // this turns on mask pixels internally AND creates mask textures efficiently openNIPlayer.setUsePointCloudsAllUsers(false);*/ // openNIPlayer.setPointCloudDrawSizeAllUsers(2); // size of each 'point' in the point cloud // openNIPlayer.setPointCloudResolutionAllUsers(2); // resolution of the mesh created for the point cloud eg., this will use every second depth pixel colorPool.push_back( ofColor( 242, 56 , 90 ) ) ; colorPool.push_back( ofColor( 245, 165 , 3 ) ) ; colorPool.push_back( ofColor( 233, 241 , 223 ) ) ; colorPool.push_back( ofColor( 74, 217 , 217 ) ) ; colorPool.push_back( ofColor( 54, 177 , 191 ) ) ; verdana.loadFont(ofToDataPath("verdana.ttf"), 24); roiArea = ofRectangle( ofRandomWidth() , ofRandomHeight() , ofRandomWidth() , ofRandomHeight() ) ; bUseRoi = false ; bFullscreen = false ; bCalibrateSpace = true ; loadRoiCalibration() ; init_ofxUI ( ) ; for ( int i = 0 ; i < 15 ; i++ ) { JointRoute jr ; jointRoutes.push_back( jr ) ; skeleton.push_back ( ofPoint() ) ; } jointRoutes[0].addIndex(1) ; jointRoutes[0].addIndex(9) ; jointRoutes[0].addIndex(12) ; jointRoutes[1].addIndex(3) ; jointRoutes[1].addIndex(6) ; jointRoutes[1].addIndex(2) ; jointRoutes[2].addIndex(-1) ; jointRoutes[3].addIndex(4) ; jointRoutes[3].addIndex(4) ; jointRoutes[4].addIndex(5) ; jointRoutes[4].addIndex(5) ; jointRoutes[5].addIndex(-1) ; jointRoutes[6].addIndex(7) ; jointRoutes[6].addIndex(7) ; jointRoutes[7].addIndex(8) ; jointRoutes[7].addIndex(8) ; jointRoutes[8].addIndex(-1) ; jointRoutes[9].addIndex(10) ; jointRoutes[10].addIndex(11) ; jointRoutes[11].addIndex(-1) ; jointRoutes[12].addIndex(13) ; jointRoutes[13].addIndex(14) ; jointRoutes[14].addIndex(-1) ; lastSpawn = 0 ; spawnDelay = 1.5f ; bDepthRegistration = false ; fbo.allocate( ofGetWidth() , ofGetHeight() , GL_RGBA ) ; fbo.begin() ; ofClear( 1 , 1 , 1, 0 ) ; fbo.end() ; bSkeletonActive = false ; }
//-------------------------------------------------------------- void testApp::setup(){ ofSetLogLevel(OF_LOG_VERBOSE); ofEnableDepthTest(); ofSetCircleResolution(64); ofSetSmoothLighting(true); ofEnableAlphaBlending(); //depthcam.init(); //depthcam.setUseTexture(false); //depthcam.open(); // profCam.setup(); profCam.setRenderBlob(true); dataset.loadFile("conLuz.xml"); calibration.init(&profCam.kinect,&dataset); calibration.enableKeys(); calibration.enableChessboardMouseControl(); rendererInited = false; //calibration.finalize(); /*cam.setPosition(0,70,100); cam.lookAt(ofVec3f(0,0,0)); fbo.allocate(1024,768,GL_RGBA); fbo.begin(); ofClear(0,0,0, 0); fbo.end();*/ sniffer.transito = &transito; transito.init(); sniffer.init(); verFija = true; cam.setDistance(20); camFija.setPosition(0,7,10); camFija.lookAt(ofVec3f(0,7,0)); luzPuntual.setPointLight(); luzPuntual.setPosition(0,5,10); luzDos.setDirectional(); luzDos.setPosition(-7,3, -5); ofEnableAlphaBlending(); maskShader.load("shaders/mixer"); altoCamara = profCam.getHeight(); anchoCamara = profCam.getWidth(); fboMezcla.allocate(anchoCamara,altoCamara); fboUno.allocate(anchoCamara,altoCamara); fboUno.begin(); ofClear(0,0,0,0); fboUno.end(); fboMensajes.allocate(anchoCamara,altoCamara); fboMensajes.begin(); ofClear(0,0,0,0); fboMensajes.end(); mensajes.push_back(new xuMensaje("Time-to-live exceeded.")); mensajes.push_back(new xuMensaje("Someone else out there?")); mensajes.push_back(new xuMensaje("UNKNOWN PACKET")); mensajes.push_back(new xuMensaje("Client Hello")); mensajes.push_back(new xuMensaje("Server Hello")); mensajesPintados = 0; //mascaraTest.loadImage("mascara.png"); //ofLoadImage(textTest,"mascara.png"); ofsetMensajes.x = 0; ofsetMensajes.y = 0; gui.addTitle("Vistas"); gui.addContent("Compuesto",fboMezcla); gui.addTitle("Mensajes"); gui.addContent("",fboMensajes); gui.addSlider("Escala",escalaMensajes, 0.001,1.5); gui.addSlider("Offset x", ofsetMensajes.x,-200,200); gui.addSlider("Offset y", ofsetMensajes.y, -200,200); gui.addTitle("Profundidad"); gui.addSlider("Distancia minima mm", profCam.minDist,300,1000); gui.addSlider("Distancia maxima mm", profCam.maxDist,1100,4000); gui.addTitle("Paquetes"); gui.addContent("Vista",fboUno); gui.addToggle("Cambiar vista", verFija); gui.addSlider("Velocidad",transito.velY,0.005,1.0); gui.addSlider("Tope de entrada",transito.maxCount, 5,500); gui.addSlider("Tiempo de espera", transito.timeMax, 50,1500); gui.addSlider("Escala", transito.escala,0.01,2); gui.addColorPicker("Uno",transito.colorUno); gui.addColorPicker("Uno",transito.colorDos); gui.addColorPicker("Uno",transito.colorTres); gui.addColorPicker("Uno",transito.colorCuatro); gui.addColorPicker("Uno",transito.colorCinco); gui.addColorPicker("Uno",transito.colorSeis); //gui.addContent("Produndidad",profCam.depthTextura); gui.loadFromXML(); }
//-------------------------------------------------------------------------- void testApp::setup() { doScreenshots = false; screenshotCount = 0; ofxDaito::setup("oscSettings.xml"); ofxConnexion::start(); ofAddListener(ofxConnexion::connexionEvent, this, &testApp::connexionEvent); ofxConnexion::setLed(false); frameScaleFactor = .6; frameW = 320 * frameScaleFactor; frameH = 240 * frameScaleFactor; int numParticles = frameW * frameH; SP.setup(frameW, frameH); SP.loadDirectory("input/otherTest/"); notifier.setup("network.xml"); notifier.enable(); ofAddListener(notifier.theEvent,this,&testApp::eventsIn); state = VIZAPP_PARTICLES_FREE; setupControlPanel(); if( bDebugMode == false ){ ofSetFullscreen(true); panel.hide(); } bJustLoadedUser = false; pointBrightness = .5; aberration = .02; aperture = .01; dofShader.load("shaders/DOFCloud"); sphereShader.load("shaders/SphereShader"); timeLastLoaded = ofGetElapsedTimef(); bDoUnload = false; PS.setup(numParticles); isMousePressed = false; chroma.allocate(targetWidth, targetHeight); chroma.begin(); ofClear(0, 0, 0, 255); chroma.end(); bTogglePlayer = panel.getValueB("toggle_mode"); for(int k = 0; k < PS.particles.size(); k++){ PS.particles[k].queueState(PARTICLE_FLOCKING, 0.0); } connexionCamera.setup(PS); currentMsg = "app started"; isSlow = false; slowState = 0; ofEnableAlphaBlending(); keyPressed('f'); keyPressed('h'); ofSetSphereResolution(16); }
//-------------------------------------------------------------- void ofApp::draw(){ renderFbo.begin(); ofClear(255,255,255,255); ofFill(); ofSetHexColor(0xe0be21); //------(a)-------------------------------------- // // draw a star // // use poly winding odd, the default rule // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofSetPolyMode(OF_POLY_WINDING_ODD); // this is the normal mode ofBeginShape(); ofVertex(200,135); ofVertex(15,135); ofVertex(165,25); ofVertex(105,200); ofVertex(50,25); ofEndShape(); //------(b)-------------------------------------- // // draw a star // // use poly winding nonzero // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofSetHexColor(0xb5de10); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(400,135); ofVertex(215,135); ofVertex(365,25); ofVertex(305,200); ofVertex(250,25); ofEndShape(); //------------------------------------- //------(c)-------------------------------------- // // draw a star dynamically // // use the mouse position as a pct // to calc nPoints and internal point radius // float xPct = (float)(mouseX) / (float)(ofGetWidth()); float yPct = (float)(mouseY) / (float)(ofGetHeight()); int nTips = 5 + xPct * 60; int nStarPts = nTips * 2; float angleChangePerPt = TWO_PI / (float)nStarPts; float innerRadius = 0 + yPct*80; float outerRadius = 80; float origx = 525; float origy = 100; float angle = 0; ofSetHexColor(0xa16bca); ofBeginShape(); for (int i = 0; i < nStarPts; i++){ if (i % 2 == 0) { // inside point: float x = origx + innerRadius * cos(angle); float y = origy + innerRadius * sin(angle); ofVertex(x,y); } else { // outside point float x = origx + outerRadius * cos(angle); float y = origy + outerRadius * sin(angle); ofVertex(x,y); } angle += angleChangePerPt; } ofEndShape(); //------------------------------------- //------(d)-------------------------------------- // // poylgon of random points // // lots of self intersection, 500 pts is a good stress test // // ofSetHexColor(0x0cb0b6); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); for (int i = 0; i < 10; i++){ ofVertex(ofRandom(650,850), ofRandom(20,200)); } ofEndShape(); //------------------------------------- //------(e)-------------------------------------- // // use sin cos and time to make some spirally shape // ofPushMatrix(); ofTranslate(100,300,0); ofSetHexColor(0xff2220); ofFill(); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); float angleStep = TWO_PI/(100.0f + sin(ofGetElapsedTimef()/5.0f) * 60); float radiusAdder = 0.5f; float radius = 0; for (int i = 0; i < 200; i++){ float anglef = (i) * angleStep; float x = radius * cos(anglef); float y = radius * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(OF_CLOSE); ofPopMatrix(); //------------------------------------- //------(f)-------------------------------------- // // ofCurveVertex // // because it uses catmul rom splines, we need to repeat the first and last // items so the curve actually goes through those points // ofSetHexColor(0x2bdbe6); ofBeginShape(); for (int i = 0; i < nCurveVertices; i++){ // sorry about all the if/states here, but to do catmull rom curves // we need to duplicate the start and end points so the curve acutally // goes through them. // for i == 0, we just call the vertex twice // for i == nCurveVertices-1 (last point) we call vertex 0 twice // otherwise just normal ofCurveVertex call if (i == 0){ ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 } else if (i == nCurveVertices-1){ ofCurveVertex(curveVertices[i].x, curveVertices[i].y); ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // to draw a curve from pt 6 to pt 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we duplicate the first point twice } else { ofCurveVertex(curveVertices[i].x, curveVertices[i].y); } } ofEndShape(); // show a faint the non-curve version of the same polygon: ofEnableAlphaBlending(); ofNoFill(); ofSetColor(0,0,0,40); ofBeginShape(); for (int i = 0; i < nCurveVertices; i++){ ofVertex(curveVertices[i].x, curveVertices[i].y); } ofEndShape(true); ofSetColor(0,0,0,80); for (int i = 0; i < nCurveVertices; i++){ if (curveVertices[i].bOver == true) ofFill(); else ofNoFill(); ofDrawCircle(curveVertices[i].x, curveVertices[i].y,4); } ofDisableAlphaBlending(); //------------------------------------- //------(g)-------------------------------------- // // ofBezierVertex // // with ofBezierVertex we can draw a curve from the current vertex // through the the next three vertices we pass in. // (two control points and the final bezier point) // float x0 = 500; float y0 = 300; float x1 = 550+50*cos(ofGetElapsedTimef()*1.0f); float y1 = 300+100*sin(ofGetElapsedTimef()/3.5f); float x2 = 600+30*cos(ofGetElapsedTimef()*2.0f); float y2 = 300+100*sin(ofGetElapsedTimef()); float x3 = 650; float y3 = 300; ofFill(); ofSetHexColor(0xFF9933); ofBeginShape(); ofVertex(x0,y0); ofBezierVertex(x1,y1,x2,y2,x3,y3); ofEndShape(); ofEnableAlphaBlending(); ofFill(); ofSetColor(0,0,0,40); ofDrawCircle(x0,y0,4); ofDrawCircle(x1,y1,4); ofDrawCircle(x2,y2,4); ofDrawCircle(x3,y3,4); ofDisableAlphaBlending(); //------(h)-------------------------------------- // // holes / ofNextContour // // with ofNextContour we can create multi-contour shapes // this allows us to draw holes, for example... // ofFill(); ofSetHexColor(0xd3ffd3); ofDrawRectangle(80,480,140,70); ofSetHexColor(0xff00ff); ofBeginShape(); ofVertex(100,500); ofVertex(180,550); ofVertex(100,600); ofNextContour(true); ofVertex(120,520); ofVertex(160,550); ofVertex(120,580); ofEndShape(true); //------------------------------------- //------(i)-------------------------------------- // // CSG / ofNextContour // // with different winding rules, you can even use ofNextContour to // perform constructive solid geometry // // be careful, the clockwiseness or counter clockwisenss of your multiple // contours matters with these winding rules. // // for csg ideas, see : http://glprogramming.com/red/chapter11.html // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofNoFill(); ofPushMatrix(); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); ofTranslate(100,0,0); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); ofTranslate(100,0,0); ofSetPolyMode(OF_POLY_WINDING_ABS_GEQ_TWO); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); ofPopMatrix(); //------------------------------------- ofSetHexColor(0x000000); ofDrawBitmapString("(a) star\nwinding rule odd", 20,210); ofSetHexColor(0x000000); ofDrawBitmapString("(b) star\nwinding rule nonzero", 220,210); ofSetHexColor(0x000000); ofDrawBitmapString("(c) dynamically\ncreated shape", 420,210); ofSetHexColor(0x000000); ofDrawBitmapString("(d) random points\npoly", 670,210); ofSetHexColor(0x000000); ofDrawBitmapString("(e) fun with sin/cos", 20,410); ofSetHexColor(0x000000); ofDrawBitmapString("(f) ofCurveVertex\nuses catmull rom\nto make curved shapes", 220,410); ofSetHexColor(0x000000); ofDrawBitmapString("(g) ofBezierVertex\nuses bezier to draw curves", 460,410); ofSetHexColor(0x000000); ofDrawBitmapString("(h) ofNextContour\nallows for holes", 20,610); ofSetHexColor(0x000000); ofDrawBitmapString("(i) ofNextContour\ncan even be used for CSG operations\nsuch as union and intersection", 260,620); renderFbo.end(); //Now draw to the screen renderFbo.draw(0,0); // Write the frame rate in green ofSetHexColor(0x00ff00); ofDrawBitmapString("Fps: " + ofToString( ofGetFrameRate()), 15,15); ofSetHexColor(0xffffff); uint64_t t = ofGetElapsedTimeMicros(); //recorder.draw(renderFbo); c.writeframe(); //ofLogNotice()<< "time recorder ="<< (ofGetElapsedTimeMicros() - t) / 1000.0<< " ms"; }
//-------------------------------------------------------------- void testApp::draw(){ if(player.isLoaded()){ //draw video player... player.getVideoPlayer().draw(videoRect); //...with feature overlay ofPushMatrix(); ofTranslate(videoRect.x, videoRect.y); ofScale(videoRect.width / player.getVideoPlayer().getWidth(), videoRect.height / player.getVideoPlayer().getHeight()); ofPushStyle(); ofNoFill(); ofSetColor(255, 0, 0); triangulate.triangleMesh.drawWireframe(); ofPopStyle(); ofPopMatrix(); //draw standard generated mesh previewFBO.begin(); ofClear(0,0,0,0); cam.begin(); glEnable(GL_DEPTH_TEST); meshBuilder.draw(player.getVideoPlayer()); glDisable(GL_DEPTH_TEST); cam.end(); previewFBO.end(); previewFBO.getTextureReference().draw(meshRect); renderFBO.begin(); ofClear(0,0,0,0); //draw triangulated mesh cam.begin(); ofPushMatrix(); ofPushStyle(); ofScale(1,-1, 1); glEnable(GL_DEPTH_TEST); player.getVideoPlayer().getTextureReference().bind(); ofEnableAlphaBlending(); /* ofSetColor(255, 255, 255, 255); glShadeModel(GL_FLAT); ofEnableLighting(); ofLight l; l.setPosition(lightX,lightY,lightZ); l.setAttenuation(0,.01,0); l.enable(); */ // triangulatedMesh.draw(); // triangulatedMesh.drawWireframe(); // ofDisableLighting(); ofSetLineWidth(1); //s ofBlendMode(OF_BLENDMODE_ADD); // triangulatedMesh.drawWireframe(); player.getVideoPlayer().getTextureReference().unbind(); latticeMesh.drawWireframe(); // glBegin(GL_POINTS); // glColor3f(1.0,0,0); // for(int i = 0; i < innerPoints.size(); i++) glVertex3f(innerPoints[i].x, innerPoints[i].y, innerPoints[i].z); // glEnd(); // //draw face normals // ofSetLineWidth(1); // for(int i = 0; i < faceNormals.size(); i++){ // ofSetColor( (faceNormals[i].x*.5+.5) * 255, // (faceNormals[i].y*.5+.5) * 255, // (faceNormals[i].z*.5+.5) * 255); // // ofLine(faceCenters[i], faceCenters[i] + faceNormals[i]*6); // } glDisable(GL_DEPTH_TEST); ofPopStyle(); ofPopMatrix(); cam.end(); renderFBO.end(); renderFBO.getTextureReference().draw(triangulatedRect); // cam.setPosition(cam.getPosition() + cam.getSideDir().normalized() * .5); if(renderMode){ ofImage saveImage; renderFBO.getTextureReference().readToPixels(saveImage.getPixelsRef()); char filename[1024]; sprintf(filename, "videframe_%05d.png", player.getVideoPlayer().getCurrentFrame()); saveImage.saveImage(filename); } } gui.draw(); }
//-------------------------------------------------------------- void testApp::update() { // Screen ofBackground(0); // Age FBO if(fboAge < 100) { fboAge++; } if(playState < 2) { kinect.update(); if(kinect.isFrameNew()) { // RGB if(tooSunny) { colorImg.setFromPixels(kinect.getPixels(), kinect.width, kinect.height); colorImg.mirror(false, true); grayImage = colorImg; // Set Timer For New BG if(ofGetMinutes() % 1 == 0) { bLearnBakground = true; } // Learn A New Background Image if (bLearnBakground == true){ grayBg = grayImage; bLearnBakground = false; } // take the abs value of the difference between background and incoming and then threshold: grayDiff.absDiff(grayBg, grayImage); grayDiff.threshold(threshold); // update the cv images grayImage.flagImageChanged(); // Find The Blobs contourFinder.findContours(grayDiff, minBlob, maxBlob, 20, false); } // IR else { grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height); grayImage.mirror(false, true); if(bThreshWithOpenCV) { grayThreshNear = grayImage; grayThreshFar = grayImage; grayThreshNear.threshold(nearThreshold, true); grayThreshFar.threshold(farThreshold); cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL); } else { unsigned char * pix = grayImage.getPixels(); int numPixels = grayImage.getWidth() * grayImage.getHeight(); for(int i = 0; i < numPixels; i++) { if(pix[i] < nearThreshold && pix[i] > farThreshold) { pix[i] = 155; } else { pix[i] = 0; } } } // update the cv images grayImage.flagImageChanged(); // Find The Blobs contourFinder.findContours(grayImage, minBlob, maxBlob, 20, false); } } // new frame // Are There Blobs ? if (contourFinder.nBlobs > 0 ) { // Draw Logo Into FBO and Fade Everything Else closePoints.begin(); ofFill(); ofSetColor(ofColor(0, 2)); ofRect(0, 0, closePoints.getWidth(), closePoints.getHeight()); ofSetColor(ofColor::white); stamp.draw(75, 0, closePoints.getWidth()- 130, closePoints.getHeight()); closePoints.end(); // Loop Through All The Blobs for (int i = 0; i < contourFinder.nBlobs; i ++) { ofVec2f frontPoint = ofVec2f (0, 0); unsigned char * pix = grayImage.getPixels(); grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height); // ??? int tempBright; int brightPixel = grayImage.getWidth()*contourFinder.blobs[i].boundingRect.getMinY() +contourFinder.blobs[i].boundingRect.getMinX(); tempBright = pix[brightPixel]; for (int j = contourFinder.blobs[i].boundingRect.getMinY(); j <= contourFinder.blobs[i].boundingRect.getMaxY(); j++){ for (int k = contourFinder.blobs[i].boundingRect.getMinX(); k <= contourFinder.blobs[i].boundingRect.getMaxX(); k++){ int brightestPixelCandidate = (grayImage.getWidth()*j+k); if (pix[brightestPixelCandidate] > tempBright) { tempBright = pix[brightestPixelCandidate]; frontPoint = ofVec2f(k,j); } } } // Trace The Contour Into A Shape ofPath blobShape ; for (int p = 0; p < contourFinder.blobs[i].pts.size(); p++) { blobShape.lineTo(contourFinder.blobs[i].pts[p]); } // Draw That Shape Into The FBO if(fboAge > 90) { closePoints.begin(); ofFill(); ofSetColor(ofColor(0,0,255)); blobShape.setFillColor(ofColor::red); blobShape.draw(); closePoints.end(); } blobShape.clear(); } } // No Blobs else { // Still Draw The Logo & Fade closePoints.begin(); ofFill(); ofSetColor(ofColor(0, 2)); ofRect(0, 0, closePoints.getWidth(), closePoints.getHeight()); ofSetColor(ofColor::white); stamp.draw(75, 0, closePoints.getWidth()- 130, closePoints.getHeight()); closePoints.end(); } // Update FBOs maskFbo.begin(); ofSetColor(ofColor::aliceBlue); // Color ?? closePoints.draw(-250, -250, maskFbo.getWidth() + 450, maskFbo.getHeight() +250); // Magic Numbers ?? maskFbo.end(); fbo.begin(); ofClear(0, 0, 0, 0); shader.begin(); shader.setUniformTexture("maskTex", maskFbo.getTextureReference(), 1); thumbnail.draw(0, 0); shader.end(); fbo.end(); // Check Brightness Every Two Seconds if(ofGetFrameNum() % 60 == 0) { currentBrightness = getCurrentBrightness(); if(currentBrightness >= targetAlpha) { //Play Media if (currentAssetIsMovie) { video.stop(); video.setFrame(0); video.play(); video.setLoopState(OF_LOOP_NONE); } else { imageTimer = 0; } playState = 2; currentBrightness = 0; } } } // play state < 2 // Idle Video if(currentAssetIsMovie) { video.update(); } if(playState == 4) { demo.update(); } // Time To Write Soem Diagnostic Info To File if(ofGetMinutes() % 10 == 0) { // Set File ofLogToFile("logs/ArtBoxLog.txt", true); // FPS ofLog() << "Frame Rate is " << ofToString(ofGetFrameRate()) << endl; // State ofLog() << "Current State is " << ofToString(playState) << endl; ofLog() << "Presenting State is " << ofToString(int(presenting)) << endl; } }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(225); ofDrawBitmapString("'s' toggles shader number 2", 10, 20); ofDrawBitmapString("'.' and '-' to switch between blendmodes", 10, 40); ofSetColor(245, 58, 135); ofFill(); // we begin fbo1 and draw the image. fbo1.begin(); ofSetColor(255); image2.draw(0, 0); fbo1.end(); // fbo2: image2. fbo2.begin(); ofSetColor(255); image1.draw(0, 0); fbo2.end(); // set tex1 and tex2: textures from fbos. ofTexture tex1 = fbo1.getTextureReference(); ofTexture tex2 = fbo2.getTextureReference(); fbo3.begin(); ofClear(0, 0, 0, 1); // we clear the fbo. shader.begin(); // shader begin: set values. shader.setUniform1f( "contrast", shadeContrast ); shader.setUniform1f( "brightness", shadeBrightness ); shader.setUniform1f( "blendmix", shadeBlendMix ); shader.setUniform1i( "blendmode", shadeBlendMode ); // so here is the trick, important one: // tex1 is the texture from fbo1. // we assign this to texture 0 , i.e. "textBase" in the shader. // this is as drawing into the fbo image1. (from shader point of view) // so instead of making : // fbo2.draw(0,0) after shader parameters we make this line: shader.setUniformTexture("texBase", tex1, 0 ); //look that is number 0: and // textures 0 are the ones used do "draw". // so we could do this making fbo1.draw. // now we have another texture in the shader: it will be number 1: shader.setUniformTexture("texBlend", tex2, 1 ); // we did not draw anything into fbo3, so to make the shader draw, we need to make our quad. // coord for the texture and for the display. // it could be a non-rectangle shape, or whatever... glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(w, 0); glVertex3f(w, 0, 0); glTexCoord2f(w, h); glVertex3f(w, h, 0); glTexCoord2f(0,h); glVertex3f(0,h, 0); glEnd(); // we do not need this: // fbo1.draw(0, 0); // because we did this: // shader.setUniformTexture("texBase", tex1, 0 ); shader.end(); // shader's end. fbo3.end(); // end of the "containing" fbo. // now we want to apply another shader, taking texture from this previous fbo3: if(doShader){ fbo3.begin(); // texture tex3 == fbo3 (shaded) ofTexture tex3 = fbo3.getTextureReference(); shader.begin(); shader.setUniform1f( "contrast", 0.7 ); shader.setUniform1f( "brightness", 0.5 ); shader.setUniform1f( "blendmix", 0.7 ); shader.setUniform1i( "blendmode", shadeBlendMode); shader.setUniformTexture("texBase", tex1, 0 ); // tex base is the same... shader.setUniformTexture("texBlend", tex3, 1 ); //now the texture to blend is fbo3., so we apply shader 2 times.... glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(w, 0); glVertex3f(w, 0, 0); glTexCoord2f(w, h); glVertex3f(w, h, 0); glTexCoord2f(0,h); glVertex3f(0,h, 0); glEnd(); //image1.draw(0, 0); shader.end(); fbo3.end(); } ofSetColor(255); //now we want to see the result: fbo3.draw(0,50); }
//-------------------------------------------------------------- void testApp::update(){ // In each cycle it�s going to update the velocity first and the the position // Each one one with a different shader and FBO. // Because on GPU you can�t write over the texture that you are reading we are // using to pair of ofFbo attached together on what we call pingPongBuffer // Learn more about Ping-Pong at: // // http://www.comp.nus.edu/~ashwinna/docs/PingPong_FBO.pdf // http://www.seas.upenn.edu/~cis565/fbo.htm#setupgl4 // Velocities PingPong // // It calculates the next frame and see if it�s there any collition // then updates the velocity with that information // velPingPong.dst->begin(); ofClear(0); updateVel.begin(); updateVel.setUniformTexture("backbuffer", velPingPong.src->getTextureReference(), 0); // passing the previus velocity information updateVel.setUniformTexture("posData", posPingPong.src->getTextureReference(), 1); // passing the position information updateVel.setUniform1i("resolution", (int)textureRes); updateVel.setUniform2f("screen", (float)width, (float)height); updateVel.setUniform1f("timestep", (float)timeStep); // draw the source velocity texture to be updated velPingPong.src->draw(0, 0); updateVel.end(); velPingPong.dst->end(); velPingPong.swap(); // Positions PingPong // // With the velocity calculated updates the position // posPingPong.dst->begin(); ofClear(0); updatePos.begin(); updatePos.setUniformTexture("prevPosData", posPingPong.src->getTextureReference(), 0); // Previus position updatePos.setUniformTexture("velData", velPingPong.src->getTextureReference(), 1); // Velocity updatePos.setUniform1f("timestep",(float) timeStep ); // draw the source position texture to be updated posPingPong.src->draw(0, 0); updatePos.end(); posPingPong.dst->end(); posPingPong.swap(); // Rendering // // 1. Sending this vertex to the Vertex Shader. // Each one it�s draw exactly on the position that match where it�s stored on both vel and pos textures // So on the Vertex Shader (that�s is first at the pipeline) can search for it information and move it // to it right position. // 2. Once it�s in the right place the Geometry Shader make 6 more vertex in order to make a billboard // 3. that then on the Fragment Shader it�s going to be filled with the pixels of sparkImg texture // renderFBO.begin(); ofClear(0,0,0,0); updateRender.begin(); updateRender.setUniformTexture("posTex", posPingPong.dst->getTextureReference(), 0); updateRender.setUniformTexture("sparkTex", sparkImg.getTextureReference() , 1); updateRender.setUniform1i("resolution", (float)textureRes); updateRender.setUniform2f("screen", (float)width, (float)height); updateRender.setUniform1f("size", (float)particleSize); updateRender.setUniform1f("imgWidth", (float)sparkImg.getWidth()); updateRender.setUniform1f("imgHeight", (float)sparkImg.getHeight()); ofPushStyle(); ofEnableBlendMode( OF_BLENDMODE_ADD ); ofSetColor(255); mesh.draw(); ofDisableBlendMode(); glEnd(); updateRender.end(); renderFBO.end(); ofPopStyle(); }