Exemplo n.º 1
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh){
	if(image.isUsingTexture()){
		ofTexture& tex = image.getTextureReference();
		if(tex.bAllocated()) {
			tex.drawSubsection(x,y,z,w,h,sx,sy,sw,sh);
		} else {
			ofLogWarning() << "ofGLRenderer::draw(): texture is not allocated";
		}
	}
}
Exemplo n.º 2
0
//----------------------------------------------------------
void ofGLRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{
	if(image.isUsingTexture()){
		const ofTexture& tex = image.getTextureReference();
		if(tex.bAllocated()) {
			tex.bind();
			draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh),false,true,false);
			tex.unbind();
		} else {
			ofLogWarning("ofGLRenderer") << "draw(): texture is not allocated";
		}
	}
}
Exemplo n.º 3
0
void
testApp::renderNoise(ofFloatImage &img)
{
    double maxval = 0.0;
    double minval = 10.0;
    
    for (int i = 0; i < img.getWidth(); i++) {
        for (int j = 0; j < img.getHeight(); j++) {
            double sum = 0;
            double scale = 1.0;
            double p[2];
            p[0] = i /(float)img.getWidth() + offset;
            p[1] = j /(float)img.getHeight();
            
            for (int k = 0; k < images.size(); k++) {
                double val = ofNoise(p[0], p[1]);
                images[k].setColor(i, j, val);
                sum += val / scale;
                scale *= alpha;
                p[0] *= beta;
                p[1] *= beta;
            }
            img.setColor(i, j, sum);
            if (sum > maxval)
                maxval = sum;
            if (sum < minval)
                minval = sum;
        }
    }
    
    if (norm) {
        for (int i = 0; i < img.getWidth(); i++) {
            for (int j = 0; j < img.getHeight(); j++) {
                float v = img.getColor(i, j).r;
                img.setColor(i, j, v/maxval);
//                img.setColor(i, j, ofMap(v, 0.0, maxval, 0.0, 1.0));
//                img.setColor(i, j, ofMap(v, minval, maxval, 0.0, 1.0));
            }
        }
    }
    
    img.update();
    
    for (ofFloatImage &i : images)
        i.update();
    
    dirty = false;
    
}
Exemplo n.º 4
0
//--------------------------------------------------------------
void testApp::draw(){

    int disp_img_w = 153;
    int disp_img_h = 120;
    int disp_img_off_x = 250;
    int disp_img_off_y = 10;
    int spc = 10;

    for (int i = 0; i < images.size(); i++) {
        int row = i / 4;
        int col = i % 4;
        ofPushMatrix();
        ofTranslate(disp_img_off_x + (disp_img_w + spc) * col, disp_img_off_y + (disp_img_h + spc) * row);
        images[i].draw(0, 0, disp_img_w, disp_img_h);
        ofPopMatrix();
    }


    ofPushMatrix();
    ofTranslate(disp_img_off_x, (disp_img_h + spc) * 2 + spc);
    img.draw(0, 0, 640, 480);
    ofPopMatrix();
    
    gui.draw();
//    ofDrawBitmapString(ofToString(ofGetFrameRate(), 0), 20, ofGetHeight() - 20);
}
Exemplo n.º 5
0
//--------------------------------------------------------------
void testApp::setup(){
    ofBackground(20);
    ofSetFrameRate(30);
    
    gui.setup("Perlin Noise", "", 20, 20);
    gui.add(alpha.setup("alpha", 2.0, 0.5, 10.0));
    gui.add(beta.setup("beta", 2.0, 0.5, 5.0));
    gui.add(octaveCnt.setup("octaves", 6, 1, 8));
    gui.add(norm.setup("normalize", true));
    gui.add(offset_incr.setup("speed", 0.0, 0.0, 0.2));
    alpha.addListener(this, &testApp::floatValChanged);
    beta.addListener(this, &testApp::floatValChanged);
    octaveCnt.addListener(this, &testApp::octaveCntChanged);
    norm.addListener(this, &testApp::boolValChanged);
    
    img.allocate(img_w, img_h, OF_IMAGE_GRAYSCALE);
    
    for (int i = 0; i < octaveCnt; i++) {
        ofImage tmp;
        tmp.allocate(img_w, img_h, OF_IMAGE_GRAYSCALE);
        images.push_back(tmp);
    }
    
    offset = 0;

}
Exemplo n.º 6
0
void renderScene(ofAutoShader& shader, ofFloatImage& xyz, ofFloatImage& confidence) {
    float mx = (float) ofGetMouseX() / ofGetWidth();
    float my = (float) ofGetMouseY() / ofGetHeight();
    shader.begin(); {
        shader.setUniformTexture("xyzMap", xyz, 0);
        shader.setUniformTexture("confidenceMap", confidence, 1);
        shader.setUniform1f("elapsedTime", ofGetElapsedTimef());
        shader.setUniform1i("frameNumber", ofGetFrameNum());
        shader.setUniform2f("mouse", ofVec2f(mx,my));
        xyz.draw(0, 0);
    } shader.end();
}
Exemplo n.º 7
0
 void draw() {
     ofEnableAlphaBlending();
     ofSetColor(255);
     ofHideCursor();
     
     renderScene(shader, xyzMap, confidenceMap);
     
     if (server->getDebug()) {
         speakerXyzMap.draw(mouseX, mouseY);
         speakerFbo.draw(mouseX, mouseY+8);
         string msg = ofToString(id) + ": " + ofToString(round(ofGetFrameRate())) + "fps";
         ofDrawBitmapString(msg, 10, 20);
     }
 }
Exemplo n.º 8
0
//--------------------------------------------------------------
void ofApp::update(){
	//Update sound engine
	ofSoundUpdate();	
	
	//Get current spectrum with N bands
	float *val = ofSoundGetSpectrum( N ); 
	//We should not release memory of val, 
	//because it is managed by sound engine

	//Update our smoothed spectrum, 
	//by slowly decreasing its values and getting maximum with val
	//So we will have slowly falling peaks in spectrum
	for ( int i=0; i<N; i++ ) {
		spectrum[i] *= 0.95; //0.97;	//Slow decreasing
		spectrum[i] = max( spectrum[i], val[i] );
	}

	//Set spectrum to spectrumImage
	spectrumImage.setFromPixels( spectrum, N, 1, OF_IMAGE_GRAYSCALE );
}
Exemplo n.º 9
0
ofFloatColor DNS::Image::Sample(const ofFloatImage & image, ofVec2f pixelCoordinate)
{
    /*
     
    (0,0)--(1,0)--(2,0)--(3,0)--(4,0)-
      |      |      |      |      |
      |      |      |      |      |
      |      |      |      |      |
    (0,1)--(1,1)--(2,1)--(3,1)--(4,1)-
      |      |      |      |      |
      |      |      |      |      |
      |      |      |      |      |
    (0,2)--(1,2)--(2,2)--(3,2)--(4,2)-
      |      |      |      |      |
     
     */
    
    int col1 = floor(pixelCoordinate.x - 0.5);
    int col2 = col1 + 1;
    col1 = MAX(0, col1);
    col2 = MIN(image.width-1, col2);
    
    int row1 = floor(pixelCoordinate.y - 0.5);
    int row2 = row1 + 1;
    row1 = MAX(0, row1);
    row2 = MIN(image.height-1, row2);
    
    float intPart;
    
    float xAmount = modf(pixelCoordinate.x - 0.5, &intPart);
    float yAmount = modf(pixelCoordinate.y - 0.5, &intPart);
    
    ofFloatColor row1Color = DNS::Color::InterpolateLinear( image.getColor(col1, row1), image.getColor(col2, row1), xAmount );
    ofFloatColor row2Color = DNS::Color::InterpolateLinear( image.getColor(col1, row2), image.getColor(col2, row2), xAmount );
    ofFloatColor finalColor = DNS::Color::InterpolateLinear( row1Color, row2Color, yAmount );
    
    return finalColor;
}
Exemplo n.º 10
0
 void setupSpeakers() {
     ofVec3f speakers[n_speakers];
     // maybe need to swap dimensions here?
     // possibly change scale too
     float eps = 0.001; // needed to avoid "== 0" check in shader
     speakers[0] = ofVec3f(0,0,0)+eps; // front left
     speakers[1] = ofVec3f(0,1,0)+eps; // front right
     speakers[2] = ofVec3f(1,1,0)+eps; // rear right
     speakers[3] = ofVec3f(1,0,0)+eps; // rear left
     
     float speakerAreaSize = 0.02;
     speakerXyzMap.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
     speakerConfidenceMap.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
     
     float* xyzPixels = speakerXyzMap.getPixels().getData();
     float* confidencePixels = speakerConfidenceMap.getPixels().getData();
     for(int i = 0; i < n_speakers; i++){
         for(int j = 0; j < n_samples; j++){
             // sample a spiral
             float angle = j * TWO_PI / 20; // 20 samples per full rotation
             float radius = ((float) j / n_samples) * speakerAreaSize; // 0 to speakerAreaSize
             // might need to swap axes here too
             xyzPixels[0] = speakers[i].x + sin(angle) * radius;
             xyzPixels[1] = speakers[i].y + cos(angle) * radius;
             xyzPixels[2] = speakers[i].z;
             xyzPixels[3] = 1;
             xyzPixels += 4;
             
             confidencePixels[0] = 1;
             confidencePixels[1] = 1;
             confidencePixels[2] = 1;
             confidencePixels[3] = 1;
             confidencePixels += 4;
         }
     }
     speakerXyzMap.update();
     speakerConfidenceMap.update();
     
     speakerFbo.allocate(n_samples, n_speakers);
     speakerPixels.allocate(n_samples, n_speakers, OF_IMAGE_COLOR_ALPHA);
 }
Exemplo n.º 11
0
//--------------------------------------------
void ofCairoRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{
	ofPixels tmp = image.getPixels();
	draw(tmp,x,y,z,w,h,sx,sy,sw,sh);
}
Exemplo n.º 12
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofEnableAlphaBlending();

	float time = ofGetElapsedTimef();
	float w = ofGetWidth();
	float h = ofGetHeight();

	fbo.begin();
	
	//Draw something on the screen

	//Set a gradient background from white to gray 
	//See "Sharp sphere example" in chapter "Creating in 3D with openFrameworks"
	ofBackgroundGradient( ofColor( 255 ), ofColor( 128 ) );

	ofSetColor( 255, 255, 255 );
	image.draw( 351, 221 );

	fbo.end();

	//Draw first image
	fbo2.begin();	
	ofBackground( 0, 0, 0 );
	float ang = time * 30;
	//ang = 0;

	ofPushMatrix();
	ofTranslate( w/2, h/2 );
	ofRotate( ang );
	ofFill();
	ofSetColor( 255, 255, 255 );
	ofTriangle( -200, -114, 200, -114, 0, 230 );
	ofPopMatrix();

	fbo2.end();

	//Enable shader
	shader.begin();
	
    //pass time value to shader
	shader.setUniform1f("time", time );
			
	//we also pass in the mouse position 
	//we have to transform the coords to what the shader is expecting which is 0,0 in the center and y axis flipped. 
	//shader.setUniform2f("mouse", mouseX - ofGetWidth()/2, ofGetHeight()/2-mouseY );
	shader.setUniformTexture( "texture1", fbo2.getTextureReference(), 1 ); //"1" means that it is texture 1

	shader.setUniformTexture( "texture2", spectrumImage.getTextureReference(), 2 ); //"2" means that it is texture 2

	//shader.setUniform1i( "N", N );
	shader.setUniform1fv( "specArray", spectrum, N );

	//Draw image through shader
	ofSetColor( 255, 255, 255 );
	fbo.draw( 0, 0 );

	//ofSetColor( 255, 255, 255, 128 );
	//fbo2.draw( 0, 0 );

	shader.end();

	//Draw spectrum
/*	ofFill();
	ofSetColor( 0, 255, 0 ); 
	for (int i=0; i<N; i++) {
		ofRect( w/2 + i * 7, h/2, 7, -spectrum[i] * 100 );
	}

	ofSetColor( 255, 255, 255 );
	spectrumImage.draw( w/2, 0, N*7, 50 );
	*/
}
float ofxShadowedTerrain::getValueFromImagePos(ofFloatImage& img, int x, int y){
    return zstretchfact * img.getColor(x,y).getBrightness();
}