示例#1
0
    void update()
	{
		fbo.begin();
			ofClear(0, 0, 0, 0);
			testImage.draw(0, 0);
        fbo.end();
    }
示例#2
0
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();
}
示例#3
0
//--------------------------------------------------------------
void testApp::draw(){
    ofSetHexColor(0xFFFFFF);
    ofBackground(0);

    if(bShowInput) grayImage.drawROI(roi.x, roi.y);
    if(bShowOutput) fbo.draw(0, 0);
    
    L.draw(pix);
    
    if(bInfo){
        ofSetHexColor(0xFF0000);
        char reportStr[1024];
    
        sprintf(reportStr, "[P] process on/off [F] snapshot [7 8 9 0] roi mask");
        ofDrawBitmapString(reportStr, 20, 10);
        sprintf(reportStr, "fps:%3.0f opencv:%3.2f madMapper:%3.2f", ofGetFrameRate(), t1, t2);
        ofDrawBitmapString(reportStr, 20, 25);
        sprintf(reportStr, "[1] show input [2] show output [i] info ");
        ofDrawBitmapString(reportStr, 20, 40);
        sprintf(reportStr, "[c] Contrast %.2f [b] Brightness %.2f ", contrast, brightness);
        ofDrawBitmapString(reportStr, 20, 55);
        sprintf(reportStr, "gray image [%4d, %4d] fbo [%4.f, %4.f] ",
                roiW, roiH, fbo.getWidth(), fbo.getHeight());
        
        int idx = (mouseY * pix.getWidth()+ mouseX) * pix.getBytesPerPixel();
        
        sprintf(reportStr, "pixels %d", pix.getPixels()[idx]);
        ofDrawBitmapString(reportStr, 20, 85);
    } 
}
	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);
	}
示例#5
0
//--------------------------------------------------------------
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 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();
    }
}
示例#7
0
文件: mdQuad.cpp 项目: tarrabass/ARM
void mdQuad::draw(ofFbo	fbo,ofShader shader){

	fbo.getTexture(0).bind();

    glBegin(GL_QUADS);
		
	glTexCoord2f(0.0,0.0);

	glVertex3f(x1, y1,  0.0);	// Bottom Left Of The Texture and Quad
  	glTexCoord2f(320,0);
	glVertex3f(x2, y2,  0.0);	// Bottom Right Of The Texture and Quad
	glTexCoord2f(320,240);  
	glVertex3f( x3,  y3,  0.0);	// Top Right Of The Texture and Quad
	glTexCoord2f(0,240);  
	glVertex3f(x4, y4,  0.0);	// Top Left Of The Texture and Quad
	glEnd();
	
    //glActiveTexture(GL_TEXTURE0);
  fbo.getTexture().unbind();

	
	if(videoOn){
		videoTexture.setPoints(x1,y1,x2,y2,x3,y3,x4,y4);
		//videoTexture.loadData(vPlayer->getPixels(), vPlayer->getWidth(), vPlayer->getHeight(), GL_RGB);
		///videoTexture.loadData(fbo.getPixels(),fbo.getWidth(), fbo.getHeight(), GL_RGB);
		
		videoTexture.draw();
	}
}
示例#8
0
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);
    
}
示例#9
0
        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();
        }
示例#10
0
void testApp::drawNormalized(ofxFaceTracker& tracker, ofBaseHasTexture& tex, ofFbo& result) {
	result.begin();
	tex.getTextureReference().bind();
	drawNormalized(tracker);
	tex.getTextureReference().unbind();
	result.end();
}
示例#11
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));
        }
示例#12
0
		// 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();
	}
示例#13
0
	Obj(ofFbo & videoFrame)
	:pixelsChanged(false)
	,createdTexPixels(false)
	{
		pixels.allocate(videoFrame.getWidth(),videoFrame.getHeight(),ofGetImageTypeFromGLType(videoFrame.getTextureReference().texData.glInternalFormat));
		updateTexture(videoFrame);
		total_num_frames++;
	}
示例#14
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();
}
示例#15
0
 void setupedFbo()
 {
     if (!mFbo.isAllocated()) {
         mFbo.allocate(getWidth(), getHeight(), GL_RGBA);
         mGlitch.setup(&mFbo);
         mGlitch.setFx(OFXPOSTGLITCH_TWIST, true);
     }
 }
示例#16
0
//--------------------------------------------------------------
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 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();
}
示例#18
0
//--------------------------------------------------------------
void center(const ofTexture& texture, ofFbo& container,  int angle) {
  if (angle % 2 == 0) {
    ofTranslate(container.getWidth() * 0.5f - texture.getWidth()  * 0.5f,
                container.getHeight() * 0.5f - texture.getHeight() * 0.5f);
  }
  else {
    ofTranslate(container.getWidth() * 0.5f - texture.getHeight() * 0.5f,
                container.getHeight() * 0.5f - texture.getWidth()  * 0.5f);
  }
}
示例#19
0
//--------------------------------------------------------------
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;
}
示例#20
0
    void setup()
	{
        ofSetLogLevel(OF_LOG_VERBOSE);
		
        testImage.loadImage("of.png");
        fbo.allocate(ofGetWidth(), ofGetHeight());
		fbo.begin();
			ofClear(0, 0, 0, 0);
		fbo.end();
    }
示例#21
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();

}
示例#22
0
	void updateTexture(ofFbo & videoFrame){
		if(!fbo.isAllocated()){
			fbo.allocate(videoFrame.getWidth(),videoFrame.getHeight(),videoFrame.getTextureReference().texData.glInternalFormat);
		}
		videoFrame.bind();
		glReadBuffer(GL_COLOR_ATTACHMENT0);
		glBindTexture(fbo.getTextureReference().texData.textureTarget, (GLuint)fbo.getTextureReference().texData.textureID);
		glCopyTexImage2D(fbo.getTextureReference().texData.textureTarget,0,fbo.getTextureReference().texData.glInternalFormat,0,0,fbo.getWidth(),fbo.getHeight(),0);
		videoFrame.unbind();
		glReadBuffer(GL_BACK);
	}
示例#23
0
	//----------
	void Scene::draw(ofFbo & fbo) {
		fbo.bind();
		
		ofPushMatrix();
		//ofScale(1.0f, -1.0f);
		//ofTranslate(0.0f, -ofGetHeight());
		
		this->draw();
		ofPopMatrix();
		
		fbo.unbind();
	}
示例#24
0
 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);
 }
示例#25
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.);
 }
示例#26
0
    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 testApp::setup(){
	light.setDirectional();
	ofEnableArbTex();
	fbo.allocate(ofGetWidth()*2, ofGetHeight()*2);
	fxaa.load("v002.FXAA.vert","v002.FXAA.frag");
	ofSetFrameRate(30);
}
//--------------------------------------------------------------
void ofxEasyFboGlitch::draw(ofFbo _fbo,float _drawX,float _drawY,float _drawW,float _drawH){
    fbo.begin();
    ofSetColor(255);
    ofBackground(0);
    _fbo.draw(0,0,fboW,fboH);
    fbo.end();
        if(glitchReset){
            reader.readToPixels(fbo, pix);
            glitchImg.setFromPixels(pix);
            glitchReset=false;
        }
        string breakImgName="glitch.jpg";
        glitchImg.saveImage(breakImgName,imgQuality);
        ofBuffer file= ofBufferFromFile(breakImgName);
        int fileSize=file.size();
        char *buffer = file.getBinaryBuffer();
        int whichByte=(int)ofRandom(fileSize);
        int whichBit =ofRandom(8);
        char bitMask = 1<< whichBit;
        buffer[whichByte] |= bitMask;
        ofBufferToFile(breakImgName,file);
        glitchImg.loadImage(breakImgName);
        if (ofRandom(1)<glitchResetProbability) {
            glitchReset=true;
        }
    glitchImg.draw(_drawX, _drawY, _drawW,_drawH);
}
示例#30
0
	void setup(){
		w=ofGetScreenWidth();
		h=ofGetScreenHeight();
		touch.init("/dev/input/event0",w,h);
		ofLog()<<touch.getName();
		fbo.allocate(w,h);
	}