Esempio n. 1
0
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 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();
	}

}
Esempio n. 3
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);
  }
}
Esempio n. 4
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);
    } 
}
Esempio n. 5
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();
	}
	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 CloudsVisualSystemNbody::meshFromFbo(ofFbo& fbo, ofMesh& mesh){
	
	mesh.addTexCoord(ofVec2f(0,0));
	mesh.addVertex(ofVec3f(0,0,0));
	
	mesh.addTexCoord(ofVec2f(fbo.getWidth(),0));
	mesh.addVertex(ofVec3f(fbo.getWidth(),0,0));
	
	mesh.addTexCoord(ofVec2f(0,fbo.getHeight()));
	mesh.addVertex(ofVec3f(0,fbo.getHeight(),0));
	
	mesh.addTexCoord(ofVec2f(fbo.getWidth(),fbo.getHeight()));
	mesh.addVertex(ofVec3f(fbo.getWidth(),fbo.getHeight(),0));
	
	mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
	
}
Esempio n. 8
0
	Obj(ofFbo & videoFrame)
	:pixelsChanged(false)
	,createdTexPixels(false)
	{
		pixels.allocate(videoFrame.getWidth(),videoFrame.getHeight(),ofGetImageTypeFromGLType(videoFrame.getTextureReference().texData.glInternalFormat));
		updateTexture(videoFrame);
		total_num_frames++;
	}
Esempio n. 9
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 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();
}
Esempio n. 11
0
		// 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();
	}
Esempio n. 12
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);
	}
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();
}
Esempio n. 14
0
 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();
 }
Esempio n. 15
0
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();
}
Esempio n. 16
0
//--------------------------------------------------------------
void testApp::update(){
    
    // Get infrarred image from kinect and transform to OpenCV image
    recordContext.update();
    recordImage.update();
    
    grayImage.setFromPixels(recordImage.ir_pixels, W, H);
    
    
    // Save background
    if(bBackground){
        saveBackground();
        bBackground = false;
    }
    
    
    // ROI mask selection
    drawRoiMask(grayImage);

 
    roi.x = MIN(roiMask[0].x, roiMask[3].x);
    roi.y = MIN(roiMask[0].y, roiMask[1].y);
    roiW = MAX(roiMask[1].x, roiMask[2].x) - roi.x;
    roiH = MAX(roiMask[3].y, roiMask[2].y) - roi.y;
    
    grayImage.setROI(roi.x, roi.y, roiW, roiH);
    backImg.setROI(roi.x, roi.y, roiW, roiH);
    grayAcc.setROI(roi.x, roi.y, roiW, roiH);
    
    
    // Opencv preprocessing
    
    t0 = ofGetElapsedTimeMillis();
    
    if(bProcess){
       // grayImage.absDiff(grayImage, backImg);
        grayImage.brightnessContrast(brightness, contrast);
        cvAdaptiveThreshold(grayImage.getCvImage(), grayImage.getCvImage(), 255);
        grayImage.blur();
        grayImage.erode();
        grayImage.dilate();
        
        grayImage.addWeighted(grayAcc, 0.1);
        grayAcc = grayImage;
        grayImage.canny(50, 150);
        
        Mat dst = grayImage.getCvImage();
        findContours(dst, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
        for (size_t i = 0; i < contours.size(); i++){
            CvPoint* pts = new CvPoint[contours[i].size()];
            for(int j = 0; j < contours[i].size(); j ++){
                pts[j].x = contours[i][j].x;
                pts[j].y = contours[i][j].y;
            }
            
            int nPts = contours[i].size();
            cvPolyLine( grayImage.getCvImage(), &pts, &nPts, 1, true, CV_RGB(255, 255, 255));
            delete[] pts;
        }
        grayImage.dilate();
        grayImage.erode();
    }
    t1 = ofGetElapsedTimeMillis() - t0;
     
    //---
    
    
	// Send image to MadMapper
    t0 = ofGetElapsedTimeMillis();
    tex.allocate(grayImage.getWidth(), grayImage.getHeight(), GL_LUMINANCE);
    tex.loadData(grayImage.getPixels(), grayImage.getWidth(), grayImage.getHeight(), GL_LUMINANCE);
    individualTextureSyphonServer.publishTexture(&tex);
    //---
    
	// Get image from MadMapper
    if(!fbo.isAllocated() || !(mClient.getWidth() == fbo.getWidth() && mClient.getHeight() == fbo.getHeight()))
        fbo.allocate(mClient.getWidth(), mClient.getHeight());
    
    fbo.begin();
    mClient.draw(0, 0);
    fbo.end();
    
    fbo.readToPixels(pix);
    
    t2 = ofGetElapsedTimeMillis() - t0;
    //---
    
    
	// Update my system
    
    L.update(mouseX, mouseY);
}
Esempio n. 17
0
		// draw texture in fbo using dimensions of fbo, filling the fbo but distorting the texture
	void ftUtil::stretch(ofFbo& _dst, ofTexture& _tex) {
		_dst.begin();
		_tex.draw(0, 0, _dst.getWidth(), _dst.getHeight());
		_dst.end();
	};
bool ofxFastFboReader::readToPixels(ofFbo &fbo, ofPixelsRef pix, ofImageType type)
{
	genPBOs();
	
	int channels;
	int glType;
	
	if (type == OF_IMAGE_COLOR)
	{
		channels = 3;
		glType = GL_RGB;
	}
	else if (type == OF_IMAGE_COLOR_ALPHA)
	{
		channels = 4;
		glType = GL_RGBA;
	}
	else if (type == OF_IMAGE_GRAYSCALE)
	{
		channels = 1;
		glType = GL_LUMINANCE;
	}
	else
	{
		return false;
	}
	
	const int width = fbo.getWidth();
	const int height = fbo.getHeight();
	
	if (async)
	{
		index = (index + 1) % num_buffers;
		nextIndex = (index + 1) % num_buffers;
	}
	else
	{
		index = nextIndex = 0;
	}
	
	size_t nb = width * height * channels;
	
	if (nb != num_bytes)
	{
		num_bytes = nb;
		setupPBOs(num_bytes);
	}
	
	glReadBuffer(GL_FRONT);
	
	fbo.bind();
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]);
	glReadPixels(0, 0, width, height, glType, GL_UNSIGNED_BYTE, NULL);
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]);
	unsigned char* mem = (unsigned char*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
	
	if (mem)
	{
		pix.setFromPixels(mem, width, height, channels);
		glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
	}
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
	
	fbo.unbind();
	
	return mem != NULL;
}
bool ofxFastFboReader::readToFloatPixels(ofFbo &fbo, ofFloatPixelsRef pix, ofImageType type)
{
	genPBOs();
	
	int channels;
	int glType;
	
	if (type == OF_IMAGE_COLOR)
	{
		channels = 3;
		glType = GL_RGB;
	}
	else if (type == OF_IMAGE_COLOR_ALPHA)
	{
		channels = 4;
		glType = GL_RGBA;
	}
	else if (type == OF_IMAGE_GRAYSCALE)
	{
		channels = 1;
		glType = GL_LUMINANCE;
	}
	else
	{
		return false;
	}
	
	const int width = fbo.getWidth();
	const int height = fbo.getHeight();
	
	if (async)
	{
		index = (index + 1) % num_buffers;
		nextIndex = (index + 1) % num_buffers;
	}
	else
	{
		index = nextIndex = 0;
	}
	
	size_t nb = width * height * channels * sizeof(float); // LS: don't just deal with 8-bit color channels..
	
	if (nb != num_bytes)
	{
		num_bytes = nb;
		setupPBOs(num_bytes);
	}
	
	glReadBuffer(GL_FRONT);
	
	fbo.bind();
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]);
	glReadPixels(0, 0, width, height, glType, GL_FLOAT, NULL);
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]);
	float* mem = (float*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
	
	if (mem)
	{
		pix.setFromPixels(mem, width, height, channels);
		//pix.setFromAlignedPixels(mem, width, height, channels, width*channels); // stride = nr of elements (float, char, etc) in a row, including padding for alignment. we assume no padding..
		glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
	}
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
	
	fbo.unbind();
	
	return mem != NULL;
}
void ofApp::mov(ofFbo &src, ofFbo &dest){
    dest.begin();
    src.draw(0,0,dest.getWidth(), dest.getHeight());
    dest.end();
}