void testApp::maskBlur(ofBaseHasTexture& tex, ofFbo& result) { int k = ofMap(mouseX, 0, ofGetWidth(), 1, 128, true); halfMaskBlur.begin(); ofClear(0, 0); maskBlurShader.begin(); maskBlurShader.setUniformTexture("tex", tex, 1); maskBlurShader.setUniformTexture("mask", faceMask, 2); maskBlurShader.setUniform2f("direction", 1, 0); maskBlurShader.setUniform1i("k", k); tex.getTextureReference().draw(0, 0); maskBlurShader.end(); halfMaskBlur.end(); result.begin(); ofClear(0, 0); maskBlurShader.begin(); maskBlurShader.setUniformTexture("tex", halfMaskBlur, 1); maskBlurShader.setUniformTexture("mask", faceMask, 2); maskBlurShader.setUniform2f("direction", 0, 1); maskBlurShader.setUniform1i("k", k); halfMaskBlur.draw(0, 0); maskBlurShader.end(); result.end(); }
void update() { for(int i = 0; i < pulses.size(); i++) { pulses[i].update(people); } fbo.begin(); ofPushStyle(); ofSetLineWidth(30); ofSetColor(0, 10); ofFill(); ofRect(0, 0, fbo.getWidth(), fbo.getHeight()); ofSetColor(255); ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); float saturation = ofMap(pulses.size(), 1, 10, 0, 255, true); for(int i = 0; i < pulses.size(); i++) { ofPushMatrix(); ofRotate(pulses[i].getAngle()); ofSetColor(ofColor::fromHsb(pulses[i].getHue(), saturation, 255)); ofLine(0, 0, ofGetWidth() / 2, 0); ofPopMatrix(); } ofPopStyle(); fbo.end(); fbo.readToPixels(fboPixels); ledRing.update(fboPixels); float presence = 0; for(int i = 0; i < people.size(); i++) { presence += people[i].getPresence(); } presence /= people.size(); midi.sendControlChange(2, 1, presence); }
void GaussianBlurFxModule::doRender(ofFbo& input) { if (m_param_enabled) { // first pass of shader: horizontal blur m_ping_pong_fbo.getPing().begin(); ofClear(0.f); m_shader.begin(); m_shader.setUniform1i("uVertical", false); // HORIZONTAL m_shader.setUniform1i("uStrength", m_param_strength); input.draw(0, 0); m_shader.end(); m_ping_pong_fbo.getPing().end(); // second pass of shader: vertical blur m_ping_pong_fbo.getPong().begin(); ofClear(0.f); m_shader.begin(); m_shader.setUniform1i("uVertical", true); // VERTICAL m_shader.setUniform1i("uStrength", m_param_strength); m_ping_pong_fbo.getPing().draw(0, 0); m_shader.end(); m_ping_pong_fbo.getPong().end(); // swap buffers: pong -> ping m_ping_pong_fbo.swap(); // draw result of shader back to input fbo input.begin(); ofClear(0.f); m_ping_pong_fbo.getPing().draw(0, 0); input.end(); } }
void testApp::drawNormalized(ofxFaceTracker& tracker, ofBaseHasTexture& tex, ofFbo& result) { result.begin(); tex.getTextureReference().bind(); drawNormalized(tracker); tex.getTextureReference().unbind(); result.end(); }
void draw(){ wc.begin(); if(!switchVideo){ wc.setUniformTexture("colorMap", img.getTexture(), 1); wc.setUniformTexture("heightMap",gray.getTexture(), 2); } else{ wc.setUniformTexture("colorMap", player.getTexture(), 1); fboDepth.begin(); player.draw(0,0); fboDepth.end(); wc.setUniformTexture("heightMap",fboDepth.getDepthTexture(),2); } wc.setUniform1f("time", ofGetElapsedTimef()*time); wc.setUniform1f("gradientStep", stepGradient); wc.setUniform1f("advectStep", advectStep); wc.setUniform1f("flipHeightMap",flipHeightMap); wc.setUniform4f("advectMatrix",advectMatrix->w,advectMatrix->x,advectMatrix->y,advectMatrix->z); fbo.draw(0,0); wc.end(); img.draw(0,0,img.getWidth()/4,img.getHeight()/4); player.draw(img.getWidth()/4,0,img.getWidth()/4,img.getHeight()/4); gui.draw(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackground(255,255,255); //Устанавливаем белый фон //1. Рисуем в буфер fbo.begin(); //Рисуем полупрозрачный белый прямоугольник, который будет создавать эффект исчезновения ofEnableAlphaBlending(); float alpha = (1-history) * 255; ofSetColor(255,255,255,alpha); ofFill(); ofRect(0,0,ofGetWidth(),ofGetHeight()); ofDisableAlphaBlending(); //Рисуем частицу ofFill(); for (int i=0; i<p.size(); ++i) { p[i].draw(); } fbo.end(); //2. Рисуем содержимое буфера на экране ofSetColor(255,255,255); fbo.draw(0,0); }
void setup(){ ofSetVerticalSync(false); w=ofGetScreenWidth(); h=ofGetScreenHeight(); ofDisableArbTex(); img.load("1.jpg"); player.load("1.mp4"); player.play(); player.setLoopState(OF_LOOP_NORMAL); gray = img; gray.setImageType(OF_IMAGE_GRAYSCALE); wc.load("wcolor.vert","wcolor.frag"); ofFbo::Settings s; s.depthStencilAsTexture=true; s.useDepth=true; s.width=w; s.height=h; fboDepth.allocate(s); fbo.allocate(w,h); fbo.begin(); ofClear(0,0,100,255); fbo.end(); gui.setup(); gui.add(stepGradient.set("step gradient", .0015, -1., 1.)); gui.add(advectStep.set("step advect", .0015, -.1, .1)); gui.add(flipHeightMap.set("flip height map", 0.7, 0., 2.)); gui.add(time.set("time", 0., 0., 1.)); gui.add(advectMatrix.set("advect matrix", ofVec4f(0.1), ofVec4f(-1.), ofVec4f(1.))); gui.add(switchVideo.set("switch video", false)); }
// draw texture in fbo using a normalized Region Of Interest void ftUtil::roi(ofFbo& _dst, ofTexture& _tex, ofRectangle _roi) { ofMesh quad; quad.setMode(OF_PRIMITIVE_TRIANGLE_FAN); quad.addVertex(glm::vec3(0,0,0)); quad.addVertex(glm::vec3(_dst.getWidth(),0,0)); quad.addVertex(glm::vec3(_dst.getWidth(),_dst.getHeight(),0)); quad.addVertex(glm::vec3(0,_dst.getHeight(),0)); float t0x = _roi.x * _tex.getWidth(); float t0y = _roi.y * _tex.getHeight(); float t1x = (_roi.x + _roi.width) * _tex.getWidth(); float t1y = (_roi.y + _roi.height) * _tex.getHeight(); quad.addTexCoord(glm::vec2(t0x, t0y)); quad.addTexCoord(glm::vec2(t1x, t0y)); quad.addTexCoord(glm::vec2(t1x, t1y)); quad.addTexCoord(glm::vec2(t0x, t1y)); _dst.begin(); ofClear(0,0); _tex.bind(); quad.draw(); _tex.unbind(); _dst.end(); }
void update() { fbo.begin(); ofClear(0, 0, 0, 0); testImage.draw(0, 0); fbo.end(); }
void Brush::moveAndDraw(float x, float y, ofFbo& fbo){ ofPushStyle(); pos.set(x, y); if (pos == lastPos || !isWorking) return; ofVec2f direc = pos - lastPos; ofVec2f perp = direc.perpendicular().normalize(); ofVec2f target, diff, sum(0,0); lastPos.set(pos); fbo.begin(); for (int i = 0; i < brushTips.size(); i ++) { target.set(perp.x * brushTipDevs[i] + x, perp.y * brushTipDevs[i] + y); brushTips[i] += (target - brushTips[i]) * 0.1; diff.set((target - brushTips[i]).normalize()); ofSetColor(128 + diff.x * 128, 128 + diff.y * 128, 0, brushTipAlphas[i]); ofLine(brushTips[i], brushTipLogs[i]); brushTipLogs[i].set(brushTips[i]); sum += brushTips[i]; } fbo.end(); ofPopStyle(); sum /= brushTips.size(); lastPos.set(sum); }
void testApp::process(ofFbo & fbo, ofImage & image, string name){ fbo.begin(); ofClear(0); shader.begin(); shader.setUniformTexture("tex", cam.getTextureReference(), 0 ); shader.setUniform2f("texSize", cam.getWidth(), cam.getHeight()); shader.setUniform2f("size", fbo.getWidth(), fbo.getHeight()); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(fbo.getWidth(), 0); glVertex3f(fbo.getWidth(), 0, 0); glTexCoord2f(fbo.getWidth(), fbo.getHeight()); glVertex3f(fbo.getWidth(), fbo.getHeight(), 0); glTexCoord2f(0,fbo.getHeight()); glVertex3f(0,fbo.getHeight(), 0); glEnd(); shader.end(); fbo.end(); TIME_SAMPLE_START(name); fbo.readToPixels(image.getPixelsRef()); //image.update(); TIME_SAMPLE_STOP(name); //image.draw(0, 0); }
void Buffer::init(ofFbo &b, const ofColor &bg) { b.allocate(); b.begin(); ofFill(); ofSetColor(bg); ofRect(0, 0, b.getWidth(), b.getHeight()); b.end(); }
//-------------------------------------------------------------- void testApp::draw(){ ofBackground(0); if ( cnt < maxDraw ) { cnt++; ofEnableAlphaBlending(); ofEnableBlendMode(OF_BLENDMODE_ADD); fbo.begin(); ofSetColor(ofColor::white, 100); vector<ofTTFCharacter> paths = font.getStringAsPoints("openframeworks"); ofPushMatrix(); ofTranslate(ofGetWidth()/2 - 800, ofGetHeight()/2 + font.getLineHeight() / 2); for( int k = 0; k < paths.size(); k++) { vector<ofPolyline> lines = paths[k].getOutline(); for( int i = 0; i < lines.size(); i++ ) { ofPolyline ll = lines[i].getResampledBySpacing(1); vector<ofPoint> pts = ll.getVertices(); for( int j = 0; j < pts.size(); j++) { int x1 = pts[j].x + ofNoise(pts[j].x) * randomVal - randomVal*0.5; int y1 = pts[j].y + ofNoise(pts[j].y) * randomVal - randomVal*0.5; int x2, y2; ofPolyline l2; vector<ofPoint> pts2; while (pts2.size() == 0) { l2 = lines[ ofRandom(lines.size()) ].getResampledBySpacing(1); pts2 = l2.getVertices(); } int randomPoint = ofRandom(pts2.size()); { x2 = pts2[randomPoint].x + ofNoise(pts2[randomPoint].x) * randomVal - randomVal*0.5; y2 = pts2[randomPoint].y + ofNoise(pts2[randomPoint].y) * randomVal - randomVal*0.5; } ofMesh mesh; mesh.setMode(OF_PRIMITIVE_LINES); mesh.addColor(ofColor(255,255,255, 80)); mesh.addColor(ofColor(255,255,255, 30)); mesh.addColor(ofColor(255,255,255, 80)); mesh.addVertex(ofVec3f(x1, y1, 0)); mesh.addVertex(ofVec3f((x1+x2)/2, (y1+y2)/2, 0)); mesh.addVertex(ofVec3f(x2, y2, 0)); mesh.drawFaces(); // ofLine(x1, y1, x2, y2); } } } ofPopMatrix(); fbo.end(); } ofSetColor(ofColor::white); fbo.draw(0, 0); }
//-------------------------------------------------------------- void testApp::draw(){ ofEnableLighting(); light.enable(); if(rotating) t++; fbo.begin(); glColor4f(1, 1, 1, 1); ofClear(0, 0, 0, 0); glPushMatrix(); glScalef(2, 2, 2); glTranslatef(ofGetWidth()/2, ofGetHeight()/2, 0); glRotatef(t, 0, 1, 1); /*glBegin(GL_QUADS); glVertex2f(-100, -100); glVertex2f(100, -100); glVertex2f(100, 100); glVertex2f(-100, 100); glEnd();*/ ofBox(0, 0, 0, 100); glPopMatrix(); fbo.end(); ofDisableLighting(); if(shading) { fxaa.begin(); fxaa.setUniformTexture("bgl_RenderedTexture", fbo.getTextureReference(0), 0); fxaa.setUniform1f("bgl_RenderedTextureWidth", fbo.getWidth()); fxaa.setUniform1f("bgl_RenderedTextureHeight", fbo.getHeight()); } else { fbo.getTextureReference(0).bind(); } glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(fbo.getWidth(), 0); glVertex2f(ofGetWidth(), 0); glTexCoord2f(fbo.getWidth(), fbo.getHeight()); glVertex2f(ofGetWidth(), ofGetHeight()); glTexCoord2f(0, fbo.getHeight()); glVertex2f(0, ofGetHeight()); glEnd(); if(shading) { fxaa.end(); } else { fbo.getTextureReference(0).unbind(); } }
void ofApp::fill(ofFbo &dest, ofFloatColor c, ofBlendMode mode){ ofPushStyle(); ofFill(); ofEnableBlendMode(mode); ofSetColor(c); dest.begin(); ofDrawRectangle(0, 0, dest.getWidth(), dest.getHeight()); dest.end(); ofPopStyle(); }
void setup() { ofSetLogLevel(OF_LOG_VERBOSE); testImage.loadImage("of.png"); fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin(); ofClear(0, 0, 0, 0); fbo.end(); }
//-------------------------------------------------------------- void testApp::setup(){ font.loadFont("Arial.ttf", 300, true, true, true); ofSetFrameRate(60); ofSetVerticalSync(true); fbo.allocate(ofGetWidth(), ofGetHeight()); fbo.begin();ofClear(0, 0, 0);fbo.end(); cnt = 0; maxDraw = 5; randomVal = 0; }
//-------------------------------------------------------------- void ofApp::draw() { fbo.begin(); ofBackground(0); // Sky sky.draw(); // Nodes ofSetColor(255); for (auto it = nodes.begin(); it != nodes.end(); it++) { it->draw(); } s.draw(); // Drawings drawing.draw(); // Constellations for (auto it = constellations.begin(); it != constellations.end(); it++) { it->draw(); } tempConstellation.draw(); // Others string str; switch (mode) { case Constellation: str = "mode: Drawing"; break; case Edge: str = "mode: Edge"; break; default: break; } ofDrawBitmapString(ofToString(ofGetFrameRate()), ofVec2f(10, 10)); fbo.end(); // fbo.draw(0, 0); //======================== get our quad warp matrix. ofMatrix4x4 mat = warper.getMatrix(); //======================== use the matrix to transform our fbo. glPushMatrix(); glMultMatrixf(mat.getPtr()); fbo.draw(0, 0); glPopMatrix(); }
void draw() { mFbo.begin(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ofSetColor(255, 255, 255); ofSetLineWidth(4); ofLine(0, getHeight() * 0.5, getWidth(), getHeight() * 0.5); mFbo.end(); mGlitch.generateFx(); mFbo.draw(0, 0); }
void setup() { ofBackground(255); trail.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA, 4); trail.begin(); ofClear(255, 0); trail.end(); derivatives.resize(3); // vel, acc, jer magnitudes.resize(3, 0); limits.resize(3, 0); limits[0] = pow(100, 1./1.); limits[1] = pow(1, 1./2.); limits[2] = pow(10, 1./3.); }
void MindPaint::draw(){ // This is for debug purpose, when the headset is not available // usually updatebrush is called inside MindPaint::update() if (useMouse && tgState != READY && appState == READY){ updateFoes(); updateBrush(); } ofBackground(0); switch (appState){ case SELECT_BG: buffer.begin(); ofSetColor((int)back.r, (int)back.g, (int)back.b); ofFill(); ofRect(0, 0, buffer.getWidth(), buffer.getHeight()); buffer.end(); Buffer::draw(buffer); ofSetColor((int)mood.r, (int)mood.g, (int)mood.b, 255); ofCircle(ofGetWidth()/2, ofGetHeight()/2, 50); break; case DRAW: buffer.begin(); brush->draw(); buffer.end(); Buffer::draw(buffer); moverControl->debugDraw(); break; case PAUSE: Buffer::draw(buffer); break; } drawMindsetStatus(useMouse ? tgEmu.args : tg.values); tgEmu.draw(); }
void update() { #ifdef USE_AUDIO //Speaker sampling code speakerFbo.begin(); renderScene(shader, speakerXyzMap, speakerConfidenceMap); speakerFbo.end(); //Read back the fbo, and average it on the CPU speakerFbo.readToPixels(speakerPixels); speakerPixels.setImageType(OF_IMAGE_GRAYSCALE); ofxOscMessage brightnessMsg; brightnessMsg.setAddress("/audio/brightness"); float* pix = speakerPixels.getData(); for(int i = 0; i < n_speakers; i++){ float avg = 0; for(int j = 0; j < n_samples; j++){ avg += *pix++; } avg /= n_samples; brightnessMsg.addFloatArg(avg); } oscSender.sendMessage(brightnessMsg); float elapsedTime = ofGetElapsedTimef(); // copied from shader --- 8< --- float t = elapsedTime / 30.; // duration of each stage float stage = floor(t); // index of current stage float i = t - stage; // progress in current stage // copied from shader --- 8< --- if(stage != previousStage) { ofxOscMessage msg; msg.setAddress("/audio/scene_change_event"); msg.addIntArg(stage == 0 ? 0 : 2); oscSender.sendMessage(msg); } previousStage = stage; if(stage == 0) { float lighthouseAngle = ofGetElapsedTimef() / TWO_PI; lighthouseAngle += 0; // set offset here ofxOscMessage msg; msg.setAddress("/audio/lighthouse_angle"); msg.addFloatArg(fmodf(lighthouseAngle, 1)); oscSender.sendMessage(msg); } #endif }
void setup() { ofSetFrameRate(60); ofSetVerticalSync(false); ledRing.setup(); fbo.allocate(512, 512); fbo.begin(); ofClear(0); fbo.end(); ofSetCircleResolution(64); ofSetLineWidth(2); ofLog() << "MIDI Ports: " << ofToString(midi.getPortList()); midi.openPort(); Pulse::midiWrapper = &midiWrapper; pulses.push_back(Pulse(0, 0)); }
void ofApp::drawBrush(ofFbo &fbo){ ofVec2f m(mouseX, mouseY); history.push_back(m); for(int i=0; i< history.size(); i++){ ofVec2f h = history[i]; if (m.match(h, ofRandom(3, 200))){ fbo.begin(); glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); ofNoFill(); ofSetColor(color, 25); ofSetLineWidth(1.53); ofLine(h.x, h.y, m.x, m.y); glDisable(GL_BLEND); fbo.end(); } } }
// draw texture in fbo using aspectratio of texture, showing the complete texture, but not filling the fbo void ftUtil::fit(ofFbo& _dst, ofTexture& _tex) { float meRatio = float(_dst.getWidth()) / float(_dst.getHeight()); // 0.5625 float texRatio = float(_tex.getWidth()) / float(_tex.getHeight()); // 1.3333 float width, height; float x0, y0, x1, y1; if (meRatio > texRatio) { height = _dst.getHeight(); width = height * texRatio; } else { width = _dst.getWidth(); height = width / texRatio; } x0 = (_dst.getWidth() - width) / 2; x1 = x0 + width; y0 = (_dst.getHeight() - height) / 2; y1 = y0 + height; ofMesh quad; quad.setMode(OF_PRIMITIVE_TRIANGLE_FAN); quad.addVertex(glm::vec3(x0,y0,0)); quad.addVertex(glm::vec3(x1,y0,0)); quad.addVertex(glm::vec3(x1,y1,0)); quad.addVertex(glm::vec3(x0,y1,0)); quad.addTexCoord(glm::vec2(0,0)); quad.addTexCoord(glm::vec2(_tex.getWidth(),0)); quad.addTexCoord(glm::vec2(_tex.getWidth(),_tex.getHeight())); quad.addTexCoord(glm::vec2(0,_tex.getHeight())); _dst.begin(); ofClear(0,0); _tex.bind(); quad.draw(); _tex.unbind(); _dst.end(); }
void ofApp::initRandom(ofFbo &target, int seed){ printf("init random %d\n", seed); ofSeedRandom(seed); ofFloatPixels newState; int w = target.getWidth(); int h = target.getHeight(); newState.allocate(w, h, OF_PIXELS_RGB); for(int x=0; x<w; x++){ for(int y=0; y<h; y++){ float r = ofSignedNoise(x,y,frame); float g = ofSignedNoise(x+11111,y+11111,frame); float b = ofSignedNoise(x+37283,y+37283,frame); newState.setColor(x,y,ofFloatColor(r,g,b)); } } target.begin(); ofImage(newState).draw(0,0,w,h); target.end(); }
void draw() { ofBackground(25); fbo.begin(); ofClear(0,0,0,0); ofEnableDepthTest(); camera.begin(); glPushMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0); if(dvel) draw_velocity(); if(dden){ draw_density(); } glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); glPopMatrix(); if( drawAxis ){ ofDrawAxis(15); } camera.end(); ofDisableDepthTest(); fbo.end(); shader.begin(); shader.setUniformTexture("tex",fbo.getTextureReference(),0); shader.setUniform2f("resolution",dw,dh); shader.setUniform1f("timer",ofGetElapsedTimef()); fbo.draw(0,0); shader.end(); gui.draw(); }
//-------------------------------------------------------------- void testApp::update() { int c = ofRandom(255); fbo.begin(); ofClear(c, c, c); fbo.end(); TIME_SAMPLE_START("PBO"); if (mode == 0) { reader.readToPixels(fbo, pix); } TIME_SAMPLE_STOP("PBO"); TIME_SAMPLE_START("readToPixels"); if (mode == 1) { fbo.readToPixels(pix); } TIME_SAMPLE_STOP("readToPixels"); }
void FakeSSSPass::render(ofFbo& readFbo, ofFbo& writeFbo, ofTexture& depthTex) { writeFbo.begin(); shader.begin(); shader.setUniformTexture("Texture", readFbo.getTextureReference(), 0); shader.setUniform3f("LightPosition", lightPosition.x, lightPosition.y, lightPosition.z); shader.setUniform1f("MaterialThickness", materialThickness); shader.setUniform3f("ExtinctionCoefficient", extinctionCoefficient.x, extinctionCoefficient.y, extinctionCoefficient.z); shader.setUniform4f("LightColor", lightColor.x, lightColor.y, lightColor.z, 1.0); shader.setUniform4f("BaseColor", baseColor.x, baseColor.y, baseColor.z, 1.0); shader.setUniform4f("SpecColor", specularColor.y, specularColor.y, specularColor.z, 1.0 ); shader.setUniform1f("SpecPower", specular); shader.setUniform1f("RimScalar", rimScale); shader.setUniform1f("AttenuationOffset", attenuationOffset); texturedQuad(0, 0, writeFbo.getWidth(), writeFbo.getHeight()); shader.end(); writeFbo.end(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); //Определяем графический буфер int w = ofGetWidth(); int h = ofGetHeight(); fbo.allocate(w,h,GL_RGB32F_ARB); //Заполняем буфер белым цветом fbo.begin(); ofBackground(255,255,255); fbo.end(); //Настраиваем параметры param.setup(); history = 0.9; time0 = ofGetElapsedTimef(); bornRate = 2500; bornCount = 0; }