Beispiel #1
0
void testApp::drawNormalized(ofxFaceTracker& tracker, ofBaseHasTexture& tex, ofFbo& result) {
	result.begin();
	tex.getTextureReference().bind();
	drawNormalized(tracker);
	tex.getTextureReference().unbind();
	result.end();
}
Beispiel #2
0
void ofxQuadWarp(ofBaseHasTexture &tex, ofPoint lt, ofPoint rt, ofPoint rb, ofPoint lb, int rows, int cols) {
    float tw = tex.getTextureReference().getWidth();
    float th = tex.getTextureReference().getHeight();

    ofMesh mesh;

    for (int x=0; x<=cols; x++) {
        float f = float(x)/cols;
        ofPoint vTop(ofxLerp(lt,rt,f));
        ofPoint vBottom(ofxLerp(lb,rb,f));
        ofPoint tTop(ofxLerp(ofPoint(0,0),ofPoint(tw,0),f));
        ofPoint tBottom(ofxLerp(ofPoint(0,th),ofPoint(tw,th),f));

        for (int y=0; y<=rows; y++) {
            float f = float(y)/rows;
            ofPoint v = ofxLerp(vTop,vBottom,f);
            mesh.addVertex(v);
            mesh.addTexCoord(ofxLerp(tTop,tBottom,f));
        }
    }

    for (float y=0; y<rows; y++) {
        for (float x=0; x<cols; x++) {
            mesh.addTriangle(ofxIndex(x,y,cols+1), ofxIndex(x+1,y,cols+1), ofxIndex(x,y+1,cols+1));
            mesh.addTriangle(ofxIndex(x+1,y,cols+1), ofxIndex(x+1,y+1,cols+1), ofxIndex(x,y+1,cols+1));
        }
    }

    tex.getTextureReference().bind();
    mesh.draw();
    tex.getTextureReference().unbind();
    mesh.drawVertices();
}
Beispiel #3
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();
}
Beispiel #4
0
void ofxDrawDisk(ofBaseHasTexture &img,float r, float slices) {
    float cx = img.getTextureReference().getWidth()/2; //center of image
    float cy = img.getTextureReference().getHeight()/2; //center of image
    float step = TWO_PI/slices; //size of a slice in radians
    
    img.getTextureReference().bind();
    
    glBegin(GL_TRIANGLE_FAN);
    for (float f=0; f<TWO_PI; f+=step) {
        glTexCoord2f(cx,cy);
        glVertex2f(0,0);
        glTexCoord2f(cx+cx*sin(f), cy+cy*cos(f));
        glVertex2f(r*sin(f), r*cos(f));
        glTexCoord2f(cx+cx*sin(f+step), cy+cy*cos(f+step));
        glVertex2f(r*sin(f+step), r*cos(f+step));
    }
    glEnd();
}
Beispiel #5
0
void testApp::maskedDraw(ofBaseHasTexture& tex) {
	ofTexture& texture = tex.getTextureReference();
	ofEnableAlphaBlending();
	maskShader.begin();
	maskShader.setUniformTexture("tex", texture, 0);
	ofSetMinMagFilters(GL_NEAREST, GL_NEAREST);
	texture.draw((int) -texture.getWidth() / 2, (int) -texture.getHeight() / 2);
	maskShader.end();
	ofDisableAlphaBlending();
}
Beispiel #6
0
	//----------
	void Scene::drawFullscreen(ofBaseHasTexture & tex) {
		glDisable(GL_DEPTH_TEST);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		
		//tex.getTextureReference().bind();
		
		const float width = tex.getTextureReference().getWidth();
		const float height = tex.getTextureReference().getHeight();
		
		ofMesh quad;
		quad.addVertex(ofVec3f(-1,-1,0));
		quad.addTexCoord(ofVec2f(0,0));
		quad.addVertex(ofVec3f(+1,-1,0));
		quad.addTexCoord(ofVec2f(width,0));
		quad.addVertex(ofVec3f(-1,+1,0));
		quad.addTexCoord(ofVec2f(0,height));
		quad.addVertex(ofVec3f(+1,+1,0));
		quad.addTexCoord(ofVec2f(width,height));
		
		quad.addIndex(0);
		quad.addIndex(1);
		quad.addIndex(3);
		
		quad.addIndex(0);
		quad.addIndex(3);
		quad.addIndex(2);
	
		quad.drawFaces();
		
		//tex.getTextureReference().unbind();
		
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
		glEnable(GL_DEPTH_TEST);
	}
Beispiel #7
0
void testApp::alphaBlur(ofBaseHasTexture& tex, ofFbo& result) {
	int k = ofMap(mouseY, 0, ofGetHeight(), 1, 25, true);
	
	halfAlphaBlur.begin();
	ofClear(0, 0);
	blurAlphaShader.begin();
	blurAlphaShader.setUniformTexture("tex", tex, 1);
	blurAlphaShader.setUniform2f("direction", 1, 0);
	blurAlphaShader.setUniform1i("k", k);
	tex.getTextureReference().draw(0, 0);
	blurAlphaShader.end();
	halfAlphaBlur.end();
	
	result.begin();
	ofClear(0, 0);
	blurAlphaShader.begin();
	blurAlphaShader.setUniformTexture("tex", halfAlphaBlur, 1);
	blurAlphaShader.setUniform2f("direction", 0, 1);
	blurAlphaShader.setUniform1i("k", k);
	halfAlphaBlur.draw(0, 0);
	blurAlphaShader.end();
	result.end();
}
Beispiel #8
0
//--------------------------------------------------------------
void ofShader::setUniformTexture(const string & name, const ofBaseHasTexture& img, int textureLocation)  const{
	setUniformTexture(name, img.getTexture(), textureLocation);
}
Beispiel #9
0
void ofxShader::setUniformTexture(const char* name, ofBaseHasTexture& img, int textureLocation) {
	setUniformTexture(name, img.getTextureReference(), textureLocation);
}
Beispiel #10
0
void ofxSetTexture(ofBaseHasTexture &material) {
    material.getTextureReference().bind();
}