Esempio n. 1
0
void testApp::makeMasked(ofImage mask, ofImage toBeMasked){
		// if you want blurrier outlines, try smaller numbers, fewer cycles than blurring.
		// mask.resize(40,30);
    mask.resize(80,60);
    mask.resize(WIDTH,HEIGHT);
    
    makeMe.setFromPixels(toBeMasked.getPixels(),WIDTH,HEIGHT,OF_IMAGE_COLOR);
    
    //then draw a quad for the top layer using our composite shader to set the alpha
	maskShader.begin();
        
        //our shader uses two textures, the top layer and the alpha
        //we can load two textures into a shader using the multi texture coordinate extensions
        glActiveTexture(GL_TEXTURE0_ARB);
        makeMe.getTextureReference().bind();
        
        glActiveTexture(GL_TEXTURE1_ARB);
        mask.getTextureReference().bind();
        //draw a quad the size of the frame
        glBegin(GL_QUADS);
            
            glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);
            glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 0);		
            glVertex2f( 0, 0);
            
            glMultiTexCoord2d(GL_TEXTURE0_ARB, WIDTH, 0);
            glMultiTexCoord2d(GL_TEXTURE1_ARB, WIDTH, 0);		
            glVertex2f( ofGetWidth(), 0);
            
            glMultiTexCoord2d(GL_TEXTURE0_ARB, WIDTH, HEIGHT);
            glMultiTexCoord2d(GL_TEXTURE1_ARB, WIDTH, HEIGHT);		
            glVertex2f( ofGetWidth(), ofGetHeight());
            
            glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, HEIGHT);
            glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, HEIGHT);		
            glVertex2f( 0, ofGetHeight());

        glEnd();
        
        //deactive and clean up
        glActiveTexture(GL_TEXTURE1_ARB);
        mask.getTextureReference().unbind();
        //mask.unbind();
        glActiveTexture(GL_TEXTURE0_ARB);
        makeMe.getTextureReference().unbind();
        
	maskShader.end();
}
Esempio n. 2
0
void testApp::setTexture(char* name, ofxShader& shader, ofImage& img, int location) {
	ofTextureData texData = img.getTextureReference().getTextureData();
	glActiveTexture(GL_TEXTURE0 + location);
	glEnable(texData.textureTarget);
	glBindTexture(texData.textureTarget, texData.textureID);
	glDisable(texData.textureTarget);
	shader.setUniform(name, location);
}
Esempio n. 3
0
void ofxShader::setSampler2d(string name, ofImage& img, int textureLocation) {
	if(bLoaded) {
		GLint uniformLocation = glGetUniformLocation((GLuint) shader, name.c_str());
		glUniform1i(uniformLocation, textureLocation);
		glActiveTexture(GL_TEXTURE0 + textureLocation);
		img.getTextureReference().bind();
	}
}
Esempio n. 4
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofImage & 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";
		}
	}
}
//----------------------------------------------------------
void ofGLRenderer::draw(const ofImage & 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.drawSubsection(x,y,z,w,h,sx,sy,sw,sh);
		} else {
			ofLogWarning("ofGLRenderer") << "drawing an unallocated texture";
		}
	}
}
Esempio n. 6
0
void ofxQuad::draw(ofImage image,int sx,int sy,int sw,int sh,int num){
    
    //   ofSetColor(255, 255, 255);
    if(moveall == 1){
        if(quadMesh.getNumVertices() < 4){
            quadMesh.draw();
        }
    }
    ofTexture bb;
    bb = image.getTextureReference();
    ofPushMatrix();
    
    // find transformation matrix
    findHomography(src, dst, matrix);
    
    //finally lets multiply our matrix
    glMultMatrixf(matrix);
    
    
    bb.drawSubsection(0,0,w,h,sx,sy,sw,sh);
    if(debug){
        
        if(active){
            ofSetColor(redColour, 255, 0,255);
        }
        else{
            ofSetColor(255, 255, 255,255);
        }
        // ofDrawBitmapString(ofToString(num), sw,sy);
        ofRect(0,0,w,h);
        
        
        //   verdana30.drawString(ofToString(num), sx,sh+sh);
        
        ofSetColor(0, 0, 0);
    }
    
    ofPopMatrix();
    
    if(debug){
        ofPushStyle();
        ofSetColor(255, 255, 255);
        ofSetLineWidth(4);
        ofLine(0, ofGetMouseY(), ofGetWidth(), ofGetMouseY());
        ofLine(ofGetMouseX(), 0, ofGetMouseX(), ofGetHeight());
        ofPopStyle();
    }
}
Esempio n. 7
0
	// ---------------------------------------------------------------------------------------
	//
	void update()
	{
		float time = ofGetElapsedTimef();
		
		ocl.begin();
		
			cl::ImageGL cl_destImage;
			ofxCL::convert( destImage.getTextureReference(), cl_destImage );
				
			ofxCL::Kernel::Ref noiseKernel = noiseProgram.getKernel( methodNames.at(methodIndex) );
			noiseKernel->global( destImage.getWidth(), destImage.getHeight() );

			float t = time * 0.1f;
		
			// ofParameters do not seem to get passed on correctly. Todo: avoid this workaround.
			float tmpLacunarity = Lacunarity;
			float tmpIncrement = Increment;
			float tmpOctaves = Octaves;
			float tmpAmplitude = Amplitude;
		
			ofVec2f bias(0,0);
		
			if( AutoMove )
			{
				bias.x = ofSignedNoise(  t, t * -0.30f ) * AutoMoveMagnitude;
				bias.y = ofSignedNoise( -t, t *  0.33f ) * AutoMoveMagnitude;
			}
				
			float tmpScale = Scale * ScaleMultiplier;
	
			if( methodIndex == 0 )
			{
				noiseKernel->call( cl_destImage, bias, ofVec2f(tmpScale,tmpScale), tmpAmplitude );
			}
			else
			{
				noiseKernel->call( cl_destImage, bias, ofVec2f(tmpScale,tmpScale), tmpLacunarity, tmpIncrement, tmpOctaves, tmpAmplitude );
			}
			
		ocl.end();
		
	}
Esempio n. 8
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofImage & image, float x, float y, float z, float w, float h){
	if(image.isUsingTexture()){
		image.getTextureReference().draw(x,y,z,w,h);
	}
}
Esempio n. 9
0
//--------------------------------------------------------------
void testApp::draw() {
	if(doRender) {
		
		ofEnableAlphaBlending();
		glEnable(GL_DEPTH_TEST);
		
		glPushMatrix();
		
		glTranslatef(width/2, 0, -width / 3);		// center scene
		static float rot = 0;
		glRotatef(rot, 0, 1, 0);			// rotate scene
		rot += rotSpeed;						// slowly increase rotation (to get a good 3D view)
		
		if(forceTimer) {
			float translateMax = forceTimer;
			glTranslatef(ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax), ofRandom(-translateMax, translateMax));
			forceTimer--;
		}
		
		
		glDisable(GL_LIGHTING);
		glBegin(GL_QUADS);
		// draw right wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(width/2, height+1, width/2);
		glColor3f(1, 1, 1);				glVertex3f(width/2, -height, width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(width/2, -height, -width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(width/2, height+1, -width/2);
		
		// back wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(width/2, height+1, -width/2);
		glColor3f(1, 1, 1);				glVertex3f(width/2, -height, -width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(-width/2, -height, -width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(-width/2, height+1, -width/2);
		
		// left wall
		glColor3f(.9, 0.9, 0.9);		glVertex3f(-width/2, height+1, -width/2);
		glColor3f(1, 1, 1);				glVertex3f(-width/2, -height, -width/2);
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(-width/2, -height, width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(-width/2, height+1, width/2);
		
		// front wall
		glColor3f(0.95, 0.95, 0.95);	glVertex3f(width/2, -height, width/2);
		glColor3f(.85, 0.85, 0.85);		glVertex3f(width/2, height+1, width/2);
		glColor3f(.9, 0.9, 0.9);		glVertex3f(-width/2, height+1, width/2);
		glColor3f(1, 1, 1);				glVertex3f(-width/2, -height, width/2);
		
		// floor
		glColor3f(.8, 0.8, 0.8);
		glVertex3f(width/2, height+1, width/2);
		glVertex3f(width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, -width/2);
		glVertex3f(-width/2, height+1, width/2);
		glEnd();
		
//		glEnable(GL_LIGHTING);
		
		// draw springs
		glColor4f(0.5, 0.5, 0.5, 0.5);
		for(int i=0; i<physics.numberOfSprings(); i++) {
			ofxMSASpring *spring = (ofxMSASpring *) physics.getSpring(i);
			ofxMSAParticle *a = spring->getOneEnd();
			ofxMSAParticle *b = spring->getTheOtherEnd();
			ofPoint vec = b->getPosition() - a->getPosition();
			float dist = msaLength(vec);
			float angle = acos( vec.z / dist ) * RAD_TO_DEG;
			if(vec.z <= 0 ) angle = -angle;
			float rx = -vec.y * vec.z;
			float ry =  vec.x * vec.z;
			
			glPushMatrix();
			glTranslatef(a->getX(), a->getY(), a->getZ());
			glRotatef(angle, rx, ry, 0.0);
			float size  = ofMap(spring->strength, SPRING_MIN_STRENGTH, SPRING_MAX_STRENGTH, SPRING_MIN_WIDTH, SPRING_MAX_WIDTH);
			
			glScalef(size, size, dist);
			glTranslatef(0, 0, 0.5);
			glutSolidCube(1);
			glPopMatrix();
		}
		

		
		// draw particles
		glAlphaFunc(GL_GREATER, 0.5);
		
		ofEnableNormalizedTexCoords();
		ballImage.getTextureReference().bind();
		for(int i=0; i<physics.numberOfParticles(); i++) {
			ofxMSAParticle *p = physics.getParticle(i);
			if(p->isFixed()) glColor4f(1, 0, 0, 1);
			else glColor4f(1, 1, 1, 1);

			glEnable(GL_ALPHA_TEST);
			
			// draw ball
			glPushMatrix();
			glTranslatef(p->getX(), p->getY(), p->getZ());
			glRotatef(180-rot, 0, 1, 0);
//			glutSolidSphere(p->getRadius(), 2, 2);
//			ofCircle(0, 0, p->getRadius());
//			ballImage.draw(0, 0, p->getRadius()*2, p->getRadius()*2);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0); glVertex2f(-p->getRadius(), -p->getRadius());
			glTexCoord2f(1, 0); glVertex2f(p->getRadius(), -p->getRadius());
			glTexCoord2f(1, 1); glVertex2f(p->getRadius(), p->getRadius());
			glTexCoord2f(0, 1); glVertex2f(-p->getRadius(), p->getRadius());
			glEnd();
			glPopMatrix();
			
			glDisable(GL_ALPHA_TEST);
			
			float alpha = ofMap(p->getY(), -height * 1.5, height, 0, 1);
			if(alpha>0) {
				glPushMatrix();
				glTranslatef(p->getX(), height, p->getZ());
				glRotatef(-90, 1, 0, 0);
				glColor4f(0, 0, 0, alpha * alpha * alpha * alpha);
//				ofCircle(0, 0, p->getRadius());
				float r = p->getRadius() * alpha;
				glBegin(GL_QUADS);
				glTexCoord2f(0, 0); glVertex2f(-r, -r);
				glTexCoord2f(1, 0); glVertex2f(r, -r);
				glTexCoord2f(1, 1); glVertex2f(r, r);
				glTexCoord2f(0, 1); glVertex2f(-r, r);
				glEnd();
				glPopMatrix();
			}
			
		}
		ballImage.getTextureReference().unbind();
		ofDisableNormalizedTexCoords();
		
		
		glPopMatrix();
	}
	
	glDisable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glColor4f(0, 0, 0, 1);
	ofDrawBitmapString( " FPS: " + ofToString(ofGetFrameRate(), 2)
					   + " | Number of particles: " + ofToString(physics.numberOfParticles(), 2)
					   + " | Number of springs: " + ofToString(physics.numberOfSprings(), 2)
					   + " | Mouse Mass: " + ofToString(mouseNode.getMass(), 2)
					   , 20, 15);
	
	
	
	
}
Esempio n. 10
0
//--------------------------------------------------------------
void testApp::setup(){
    img.loadImage("fill.png");
    ktex.setTexture(img.getTextureReference());

}
//--------------------------------------------------------------
void testApp::draw(){
	glPushMatrix();
	
	glTranslatef(ofGetWidth()/2, 0, 0);
	glRotatef(currentRot, 0, 1, 0);
	
	ofSetColor(255);
	
	glEnable(GL_DEPTH_TEST);
	glPointSize(pointSize);
	
	if(useTexture) image.getTextureReference().bind();		// new in OF006
	if(useSprite) {
		glEnable(GL_POINT_SPRITE);
		glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
	}	
	
    switch(drawMode) {
        case kModeVA:
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_COLOR_ARRAY);
            
            glVertexPointer(3, GL_FLOAT, 0, pos);
            glColorPointer(4, GL_FLOAT, 0, col);
            
            glDrawArrays(GL_POINTS, 0, numParticles);
            
            glDisableClientState(GL_VERTEX_ARRAY); 
            glDisableClientState(GL_COLOR_ARRAY);
            break;
            
        case kModeVBO:
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_COLOR_ARRAY);
            
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0]);
            glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 3 * sizeof(float), pos);
            glVertexPointer(3, GL_FLOAT, 0, 0);
            
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1]);
            glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, numParticles * 4 * sizeof(float), col);
            glColorPointer(4, GL_FLOAT, 0, 0);
            
            
            glDrawArrays(GL_POINTS, 0, numParticles);
            
            glDisableClientState(GL_VERTEX_ARRAY); 
            glDisableClientState(GL_COLOR_ARRAY);
            
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
            break;
            
        case kModeNormal:
        default:
            glBegin(GL_POINTS);
            for(int i=0; i<numParticles; i++) {
                glColor4f(col[i][0], col[i][1], col[i][2], col[i][3]);
                glVertex3f(pos[i][0], pos[i][1], pos[i][2]);
            }
            glEnd();
	}
	
	if(useTexture) image.getTextureReference().unbind();		// new in OF006
	
	if(useSprite) {
		glDisable(GL_POINT_SPRITE);
	}
	
	glDisable(GL_DEPTH_TEST);	
	glPopMatrix();
    
    // black rectangle for text
	ofSetColor(0);
	ofRect(0, 0, 200, 200);
    
	ofSetColor(255);
	ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate(), 2) + "\n" + 
					   "numParticles: " + ofToString(numParticles) + "\n" + 
                       "immediate mode (1): " + (drawMode == kModeNormal ? "X" : "") + "\n" + 
                       "useVA (2): " + (drawMode == kModeVA ? "X" : "") + "\n" + 
                       "useVBO (3): " + (drawMode == kModeVBO ? "X" : "") + "\n" + 
                       "useTexture (t): " + (useTexture ? "X" : "") + "\n" + 
                       "useSprite (s): " + (useSprite ? "X" : "") + "\n" + 
                       "vsync (v): " + (vsync ? "X" : "") + "\n" + 
                       "pointSize []: " + ofToString(pointSize)
                       
                       , 20, 20);
}