Example #1
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofPath & shape){
	ofColor prevColor;
	if(shape.getUseShapeColor()){
		prevColor = ofGetStyle().color;
	}
	if(shape.isFilled()){
		ofMesh & mesh = shape.getTessellation();
		if(shape.getUseShapeColor()){
			setColor( shape.getFillColor() * ofGetStyle().color,shape.getFillColor().a/255. * ofGetStyle().color.a);
		}
		draw(mesh);
	}
	if(shape.hasOutline()){
		float lineWidth = ofGetStyle().lineWidth;
		if(shape.getUseShapeColor()){
			setColor( shape.getStrokeColor() * ofGetStyle().color, shape.getStrokeColor().a/255. * ofGetStyle().color.a);
		}
		setLineWidth( shape.getStrokeWidth() );
		vector<ofPolyline> & outlines = shape.getOutline();
		for(int i=0; i<(int)outlines.size(); i++)
			draw(outlines[i]);
		setLineWidth(lineWidth);
	}
	if(shape.getUseShapeColor()){
		setColor(prevColor);
	}
}
//----------------------------------------------------------
void ofGLRenderer::draw(const ofPath & shape) const{
	ofColor prevColor;
	if(shape.getUseShapeColor()){
		prevColor = ofGetStyle().color;
	}
	ofGLRenderer * mut_this = const_cast<ofGLRenderer*>(this);
	if(shape.isFilled()){
		const ofMesh & mesh = shape.getTessellation();
		if(shape.getUseShapeColor()){
			mut_this->setColor( shape.getFillColor(),shape.getFillColor().a);
		}
		draw(mesh,OF_MESH_FILL);
	}
	if(shape.hasOutline()){
		float lineWidth = ofGetStyle().lineWidth;
		if(shape.getUseShapeColor()){
			mut_this->setColor( shape.getStrokeColor(), shape.getStrokeColor().a);
		}
		mut_this->setLineWidth( shape.getStrokeWidth() );
		const vector<ofPolyline> & outlines = shape.getOutline();
		for(int i=0; i<(int)outlines.size(); i++)
			draw(outlines[i]);
		mut_this->setLineWidth(lineWidth);
	}
	if(shape.getUseShapeColor()){
		mut_this->setColor(prevColor);
	}
}
//--------------------------------------------------------------
ofMesh ofApp::createMeshFromPath(ofPath path, float thickness){
	ofMesh mesh;
	// get outline of original path (for sides)
	vector <ofPolyline> outline = path.getOutline();
	// add front to mesh
	mesh.append(path.getTessellation());
	// get number of vertices in original path
	int numVerts = mesh.getNumVertices();
	// define offset based on thickness
	ofVec3f offset = ofVec3f(0, 0, -thickness);
	// translate path
	path.translate(offset);
	// add back to mesh
	mesh.append(path.getTessellation());
	// add sides to mesh (via indices)
	for(int j = 0; j < outline.size(); j++){
		int outlineSize = outline[j].getVertices().size();
		vector <int> outlineIndices;
		for(int i = 1; i < outlineSize; i++){
			ofVec3f & v = outline[j].getVertices()[i];
			int originalIndex = -1;
			for(int k = 0; k < numVerts; k++){
				if(v.match(mesh.getVertices()[k])){
					originalIndex = k;
					break;
				}
			}
			outlineIndices.push_back(originalIndex);
		}
		for(int i = 0; i < outlineIndices.size(); i++){
			const int a = outlineIndices[i];
			const int b = outlineIndices[(i + 1) % outlineIndices.size()];
			const int c = outlineIndices[i] + numVerts;
			const int d = outlineIndices[(i + 1) % outlineIndices.size()] + numVerts;
			mesh.addTriangle(a, b, c);
			mesh.addTriangle(c, b, d);
		}
	}
	return mesh;
}
Example #4
0
// -----------------------------------
void Letter::setup(ofPath letter, float depth)
{    
    // Tessellation is subdividing a concave polygon into convex polygons.
    front = letter.getTessellation();
    back = front;  
    
    // Loop through all of the vertices in the "back" mesh
    // and move them back in on the "z" axis
    vector<ofPoint>& f = front.getVertices();
    vector<ofPoint>& b = back.getVertices();
    for(int j=0; j< f.size(); j++)
    {
        f[j].z += depth/2.0;
        b[j].z -= depth/2.0;
    }
}
Example #5
0
//--------------------------------------------------------------
void testApp::draw(){
    
    //curve eq
    if (drawEQ) {
        ofPushMatrix();
        ofTranslate(600, ofGetHeight() - 50);
        ofMesh eq_mesh = eq_path.getTessellation();
        eq_mesh.drawVertices();
        ofPopMatrix();
    }
    
    /* see what the fbo has in it */
    if (drawFBO) {
        ofPushMatrix();
        ofTranslate(50, 50);
        ofDrawBitmapString("FBO", 0, 0);
        ofPopMatrix();
        
        ofPushMatrix();
        ofTranslate(50, 70);
        posbuf.src->getTextureReference().bind();
        
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
        glTexCoord2f(fbo_res, 0); glVertex3f(fbo_res, 0, 0);
        glTexCoord2f(fbo_res, fbo_res); glVertex3f(fbo_res, fbo_res, 0);
        glTexCoord2f(0, fbo_res); glVertex3f(0, fbo_res, 0);
        glEnd();
        
        posbuf.src->getTextureReference().unbind();
        ofPopMatrix();
    }
    
    //actual sphere
    
    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    
    cam.begin();
    
    if (autoRotate) {
        ofRotateY(-30);
        ofRotateX(ang += angincr);
        ofRotateZ(ofGetFrameNum() * 0.005);
    } else {
        ofRotateX(0.0);
        ofRotateY(0.0);
        ofRotateZ(0.0);
    }
    
    glEnable(GL_POINT_SMOOTH);
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    
    shader.begin();
    shader.setUniformTexture("u_OffMap", posbuf.src->getTextureReference(), 0);
    shader.setUniform1f("u_fboRes", (float)fbo_res);
    
    vm.drawVertices();
    
    shader.end();
    
    glDisable(GL_POINT_SMOOTH);
    
    cam.end();
    ofPopMatrix();
}
Example #6
0
//--------------------------------------------------------------
void testApp::update(){
    
    /* get the spectral data */
    float * val = ofSoundGetSpectrum(nBandsToGet);
	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 (fftSmoothed[i] > fftmax) {
            fftmax = fftSmoothed[i];
        }
	}
    
    /* update our bark map'd frequency bins */
    memset(bins, 0x00, sizeof(bins));
    for (int i = 0; i < SPECTRAL_BANDS; i++) {
        int idx = barkmap[i];
        bins[idx] += fftSmoothed[i] * 20;
    }
    
    /* put the eq vals into a path to turn them into a curve */
    int line_len = fbo_res;
    float ppseg = line_len /(float)(BARK_MAX+1);
    eq_path.clear();
    eq_path.curveTo(0, -bins[0]);
    for (int i = 0; i < BARK_MAX; i++) {
        //        bins[i] = max(5.0f, bins[i]); //set a lower bound on the bin val
        eq_path.curveTo(i * ppseg, -bins[i]);
    }
    
    //    eq_path.curveTo(BARK_MAX * ppseg, -bins[0]);
    //    eq_path.curveTo(BARK_MAX * ppseg, -bins[0]);
    
    //smooth this out a little at the end so the eq texture wraps, 25 = BARK_MAX
    eq_path.curveTo(25 * ppseg, -(bins[0] + bins[24] + bins[23] + bins[22])/4.0f);
    eq_path.curveTo(26 * ppseg, -bins[0]);
    eq_path.curveTo(26 * ppseg, -bins[0]);
    
    ofMesh eq_m = eq_path.getTessellation();
    
    //load up the eq curve into a texture
    eq_tex.loadData((float *)eq_m.getVerticesPointer(), fbo_res, 1, GL_RGB);
    
    //update where on the axis we will apply the latest eq data
    axis_loc--;
    
    if (axis_loc < 0)
        axis_loc = fbo_res;
    
    //use fbo to work out displacement coeffcients
    posbuf.dst->begin();
    ofClear(0);
    pos_shader.begin();
    pos_shader.setUniformTexture("u_prevDisp", posbuf.src->getTextureReference(), 0);
    pos_shader.setUniformTexture("u_newDisp", eq_tex, 1); //pass the new displacement data
    pos_shader.setUniform1f("u_axisloc", axis_loc);
    pos_shader.setUniform1f("u_decayRate", posdecayrate);
    
    ofSetColor(255, 255, 255, 255);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
    glTexCoord2f(fbo_res, 0); glVertex3f(fbo_res, 0, 0);
    glTexCoord2f(fbo_res, fbo_res); glVertex3f(fbo_res, fbo_res, 0);
    glTexCoord2f(0, fbo_res); glVertex3f(0, fbo_res, 0);
    glEnd();
    
    pos_shader.end();
    posbuf.dst->end();
    posbuf.swap();
    
}