示例#1
0
	void Output::publishTexture(ofTexture &tex)
	{
		assert(mutex);

		if (tex.getWidth() == uiFrameWidth
			&& tex.getHeight() == uiFrameHeight)
		{
			ofPixels pix2;
			tex.readToPixels(pix2);

			mutex->lock();
			if (!back_buffer->isAllocated() ||
				back_buffer->getWidth() != tex.getWidth() ||
				back_buffer->getHeight() != tex.getHeight()) {
				back_buffer->allocate(tex.getWidth(), tex.getHeight(), pix2.getNumChannels());
			}
			memcpy(&back_buffer->getData()[1], pix2.getData(), pix2.size() - 1);

			if (back_buffer->getNumChannels() != 4)
				back_buffer->setNumChannels(4);

			has_new_frame = true;

			mutex->unlock();
		}
		else
			ofLogError("ofxDeckLinkAPI::Output") << "invalid texture size";
	}
示例#2
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();
	}
示例#3
0
	//----------
	bool Sender::send(const ofTexture & texture, bool flipY) {
		try {
			if (!this->isInitialized()) {
				throw("Not initialised");
			}

			//check if the sender matches the settings of the texture
			if (this->width != texture.getWidth() || this->height != texture.getHeight()) {
				this->width = texture.getWidth();
				this->height = texture.getHeight();

				//update the sender to match local settings
				char mutableName[256];
				strcpy_s(mutableName, channelName.size() + 1, channelName.c_str());
				if (!this->spoutSender->UpdateSender(mutableName, this->width, this->height)) {
					throw("Can't update sender");
				}
				this->channelName = string(mutableName);
			}

			//send texture and retain any fbo bound for drawing
			GLint drawFboId = 0;
			glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
			this->spoutSender->SendTexture(texture.getTextureData().textureID, texture.getTextureData().textureTarget, this->width, this->height, flipY, drawFboId);
			return true;
		}
		catch (const char * e) {
			ofLogError("ofxSpout::Sender::send") << e;
			return false;
		}
	}
void ofxSimpleMask::drawMask ( ofTexture contentTex , ofTexture maskTex ,
							   float xOffset , float yOffset , float contentAlpha , float width , float height )
{

	if ( width == 0 ) width = maskArea.width ; 
	if ( height == 0 ) height = maskArea.height ; 
    //BEGIN MASK
    ofEnableAlphaBlending( ) ;

		glActiveTexture(GL_TEXTURE0_ARB);
		contentTex.bind();

		glActiveTexture(GL_TEXTURE1_ARB);
		maskTex.bind();

            //prevents weird texture wrapping , otherwise the last or first pixel is repeated to infinity
            contentTex.setTextureWrap( GL_CLAMP_TO_BORDER_ARB , GL_CLAMP_TO_BORDER_ARB ) ;
            //contentTex.setTextureWrap( GL_CLAMP , GL_CLAMP ) ;


            maskShader->begin();

                maskShader->setUniformTexture("Tex0", contentTex , 0);
                maskShader->setUniformTexture("Tex1", maskTex , 1);
                maskShader->setUniform1f( "alpha" , contentAlpha ) ;
                glBegin(GL_QUADS);
                ofFill() ;

                glMultiTexCoord2d(GL_TEXTURE0_ARB, xOffset , yOffset );
                glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 0 );
                glVertex2f( maskArea.x ,  maskArea.y );


                glMultiTexCoord2d(GL_TEXTURE0_ARB, xOffset + contentTex.getWidth(), yOffset );
                glMultiTexCoord2d(GL_TEXTURE1_ARB, maskTex.getWidth(), 0 );
                glVertex2f(  maskArea.x + width , maskArea.y );


                glMultiTexCoord2d(GL_TEXTURE0_ARB, xOffset + contentTex.getWidth() , contentTex.getHeight() + yOffset );
                glMultiTexCoord2d(GL_TEXTURE1_ARB, maskTex.getWidth() , maskTex.getHeight() );
                glVertex2f(  maskArea.x + width  , height + maskArea.y );

                glMultiTexCoord2d(GL_TEXTURE0_ARB, xOffset , contentTex.getHeight() + yOffset );
                glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, maskTex.getHeight()  );
                glVertex2f(  maskArea.x , height + maskArea.y ) ;

                glEnd();

            maskShader->end() ;
		//deactive and clean up
		glActiveTexture(GL_TEXTURE1_ARB);
		maskTex.unbind();

		glActiveTexture(GL_TEXTURE0_ARB);
		contentTex.unbind();

		//maskArea = originalMaskArea ;
}
示例#5
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);
  }
}
    void copy(S& src, ofTexture& tex) {
        imitate(tex, src);
        int w = tex.getWidth(), h = tex.getHeight();
        int glType = tex.getTextureData().glTypeInternal;
        Mat mat = toCv(src);
		tex.loadData(mat.ptr(), w, h, glType);
    }
void LayoutVerticalStripes::render(ofTexture texture, ColorChannel *colorChannel, Layer layer) {
    float complexity = layer.complexity;
    int nrows = (complexity * 128) + 1;
    int ncols = 1;
    int xSize = ofGetWidth() / nrows;
    int ySize = ofGetHeight() / ncols;
    for (int row=0; row<nrows; row++) {
        for (int col=0; col<ncols; col++) {
            ofColor selectedColor = colorChannel->selectColor(nrows * col + row + layoutFrame);
            shader.begin(texture.getWidth(),
                         texture.getHeight(),
                         layer.masterScreenAlpha,
                         layer.alpha,
                         layer.contrast,
                         layer.luminance,
                         selectedColor.r,
                         selectedColor.g,
                         selectedColor.b);
            int xOffset = row * xSize;
            int yOffset = col * ySize;
            texture.draw(xOffset, yOffset, xSize, ySize);
            shader.end();
        }
    }
}
	void OpenCLImage::initFromTexture(ofTexture &tex,
									  cl_mem_flags memFlags,
									  int mipLevel)
	{
		
		ofLog(OF_LOG_VERBOSE, "OpenCLImage::initFromTexture");
		
		init(tex.getWidth(), tex.getHeight(), 1);
		
		cl_int err;
		if(clMemObject) clReleaseMemObject(clMemObject);
		
		clMemObject = clCreateFromGLTexture2D(pOpenCL->getContext(), memFlags, tex.getTextureData().textureTarget, mipLevel, tex.getTextureData().textureID, &err);
		assert(err != CL_INVALID_CONTEXT);
		assert(err != CL_INVALID_VALUE);
		//	assert(err != CL_INVALID_MIPLEVEL);
		assert(err != CL_INVALID_GL_OBJECT);
		assert(err != CL_INVALID_IMAGE_FORMAT_DESCRIPTOR);
		assert(err != CL_OUT_OF_HOST_MEMORY);
		assert(err == CL_SUCCESS);
		assert(clMemObject);
		
		texture = &tex;
		hasCorrespondingGLObject = true;
	}
void ofxSimpleMask::drawScrollingMask( ofTexture content , ofTexture mask , float scrolling , float contentAlpha )
{
    
    content.setTextureWrap( GL_CLAMP_TO_BORDER_ARB , GL_CLAMP_TO_BORDER_ARB ) ;
    
    glActiveTexture(GL_TEXTURE0_ARB);
    content.bind() ;
    
    glActiveTexture(GL_TEXTURE1_ARB);
    mask.bind() ;

    //ofTranslate ( 0 , offset.y + 100 , 0 ) ;
    
    //draw a quad the size of the frame
    glBegin(GL_QUADS);
    ofFill() ;
    ofSetColor ( 255 , 255 , 255 , 255 ) ;
    
    int fadeMaskOffset = 0 ;
    
    //move the mask around with the mouse by modifying the texture coordinates
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, scrolling );
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 0);
    glVertex2f( 0 , fadeMaskOffset  );
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, content.getWidth(), scrolling );
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth(), 0 );
    glVertex2f(  maskArea.width , fadeMaskOffset );
    
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, content.getWidth() , mask.getHeight() + scrolling );
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() , mask.getHeight() );
    glVertex2f(  maskArea.width  ,  maskArea.height + fadeMaskOffset );
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, mask.getHeight() + scrolling );
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, mask.getHeight()  );
    glVertex2f( 0 , maskArea.height + fadeMaskOffset ) ;
    
    glEnd();
    
    //deactive and clean up
    glActiveTexture(GL_TEXTURE1_ARB);
    mask.unbind() ; 
    
    glActiveTexture(GL_TEXTURE0_ARB);
    content.unbind() ;
}
示例#10
0
	Obj(ofTexture & videoFrame)
	:pixelsChanged(false)
	,createdTexPixels(false)
	{
		pixels.allocate(videoFrame.getWidth(),videoFrame.getHeight(),ofGetImageTypeFromGLType(videoFrame.texData.glInternalFormat));
		updateTexture(videoFrame);
		total_num_frames++;
	}
void dpMarionette::drawBasicRibbon(ofTexture &tex,
								   const ramNode &nodeA,const ramNode &nodeB,
								   float width, int resolution,
								   int A_Axis, int B_Axis,
								   bool wired,int beginOffset, int endOffset,
								   ofVec3f beginOffset3v,ofVec3f endOffset3v){

	ofNode parent[2];
	parent[0] = nodeA;
	parent[1] = nodeB;

	ofNode child[4];
	child[0].setParent(parent[0]);
	child[1].setParent(parent[0]);
	child[2].setParent(parent[1]);
	child[3].setParent(parent[1]);

	ofVec3f aPos,bPos;
	if (A_Axis == DPM_AXIS_X) aPos.set(width/2.0, beginOffset, 0.0);
	if (A_Axis == DPM_AXIS_Y) aPos.set(0.0, width/2.0, 0.0);
	if (A_Axis == DPM_AXIS_Z) aPos.set(0.0, beginOffset, width/2.0);

	if (B_Axis == DPM_AXIS_X) bPos.set(width/2.0, endOffset, 0.0);
	if (B_Axis == DPM_AXIS_Y) bPos.set(0.0, width/2.0, 0.0);
	if (B_Axis == DPM_AXIS_Z) bPos.set(0.0, endOffset, width/2.0);

	child[0].setPosition(aPos.x * -1, aPos.y, aPos.z * -1);
	child[1].setPosition(aPos);
	child[2].setPosition(bPos.x * -1, bPos.y, bPos.z * -1);
	child[3].setPosition(bPos);

	child[0].setPosition(child[0].getPosition() + beginOffset3v);
	child[1].setPosition(child[1].getPosition() + beginOffset3v);
	child[2].setPosition(child[2].getPosition() + endOffset3v);
	child[3].setPosition(child[3].getPosition() + endOffset3v);

	ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight());
	ofVec3f targA,targB;
	float sliceP;

	tex.bind();
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0;i < resolution + 1;i++){
		sliceP = i/float(resolution);
		targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(),
														  sliceP);
		targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(),
														  sliceP);
		glTexCoord2d(0.0, texSize.y * sliceP);
		glVertex3d(targA.x, targA.y, targA.z);
		glTexCoord2d(texSize.x, texSize.y * sliceP);
		glVertex3d(targB.x, targB.y, targB.z);
	}
	glEnd();
	tex.unbind();

}
示例#12
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();
	}
示例#13
0
	void updateTexture(ofTexture & videoFrame){
		if(!fbo.isAllocated()){
			fbo.allocate(videoFrame.getWidth(),videoFrame.getHeight(),videoFrame.texData.glInternalFormat);
		}
		fbo.begin();
		videoFrame.bind();
		ofMesh mesh;
		mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
		mesh.addTexCoord(ofVec2f(0,0));
		mesh.addTexCoord(ofVec2f(videoFrame.getWidth(),0));
		mesh.addTexCoord(ofVec2f(videoFrame.getWidth(),videoFrame.getHeight()));
		mesh.addTexCoord(ofVec2f(0,videoFrame.getHeight()));
		mesh.addVertex(ofVec3f(0,0));
		mesh.addVertex(ofVec3f(videoFrame.getWidth(),0));
		mesh.addVertex(ofVec3f(videoFrame.getWidth(),videoFrame.getHeight()));
		mesh.addVertex(ofVec3f(0,videoFrame.getHeight()));
		mesh.draw();
		videoFrame.unbind();
		fbo.end();
	}
示例#14
0
//--------------------------------------------------------------
void applyRotation(const ofTexture &texture, int angle) {
  ofRotate(angle * 90);
  
  switch (angle) {
      
    case Rotate90:
      ofTranslate( 0, -texture.getHeight() );
      break;
      
    case Rotate180:
      ofTranslate( -texture.getWidth(), -texture.getHeight() );
      break;
      
    case Rotate270:
      ofTranslate( -texture.getWidth(), 0 );
      break;
      
    default: break;
  }
}
示例#15
0
void Brush::pickColorFrom(ofTexture &_tex, float _lerpAmount, float _randAmount){
    
    ofRectangle palleteArea(0,0,_tex.getWidth(),_tex.getHeight());
    
    ofFloatPixels pixels;
    pixels.allocate(_tex.getWidth(), _tex.getHeight(), OF_IMAGE_COLOR_ALPHA);
    _tex.readToPixels(pixels);
    
    for(int i = 0; i < Bs.size(); i++){
        
        if ( palleteArea.inside( *Bs[i] ) ){
        
            ofFloatColor color = pixels.getColor(Bs[i]->x, Bs[i]->y);
            Bs[i]->color.lerp(color, _lerpAmount * color.a);
            Bs[i]->color.setHue( Bs[i]->color.getHue() + ofRandom(-_randAmount,_randAmount) );
            colors[i].set(Bs[i]->color);
            colors[i].a = 1.0;
        }
    }
}
示例#16
0
void GLTexture::initFromOFTexture(ofTexture &texture)
{
	tex[0] = texture.getTextureData().textureID;
	type = texture.texData.glType;
	texTarget = texture.texData.textureTarget;			//texTarget  GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB, 
	texInternalFormat = texture.texData.glTypeInternal;  //GL_RGBA, GL_RGBA16F_ARB, GL_RGBA32F_ARB;
	minFilter = GL_LINEAR;		//GL_NEAREST, GL_LINEAR
	magFilter = GL_LINEAR;		//GL_NEAREST, GL_LINEAR
	width = texture.getWidth();
	height = texture.getHeight();

}
示例#17
0
VoronoiFilter::VoronoiFilter(ofTexture & texture) : AbstractFilter(texture.getWidth(), texture.getHeight()) {
    _name = "Voronoi";
    _texture = texture;
    for (int i=0; i<NUM_POINTS; i++) {
        _vertices[i*2] = ofRandomuf();
        _vertices[i*2+1] = ofRandomuf();
        _colors[i*3] = ofRandomuf();
        _colors[i*3+1] = ofRandomuf();
        _colors[i*3+2] = ofRandomuf();
    }
    _addParameter(new Parameter2fv("verts", _vertices, NUM_POINTS));
    _addParameter(new Parameter3fv("colors", _colors, NUM_POINTS));
    _setupShader();
}
示例#18
0
void Puppet::setup(string paintingID, ofTexture tex, vector<ofPolyline> lines, ofPoint pos)
{
    this->tex = tex;
    this->pos = pos;
    this->lines = lines;
    scale = 1.0;
    rot = 0.0;
    
    if (!lines.empty())
    {
        ofPolyline line = lines.at(0);
        
        line = line.getResampledBySpacing(20);
        line.getVertices().erase(line.getVertices().begin());
        
        if (line.size() > 5)
        {
            ofPolyline lineForTri = line;
            ofVec2f tweakForDeformer(tex.getWidth()/2, tex.getHeight()/2);
            ofVec2f centroid = lineForTri.getCentroid2D();
            for (auto& p : lineForTri.getVertices())
            {
                // enlarge from centroid
//                ofVec2f dir = (p - centroid).getNormalized();
//                p += dir * 15;
                p -= tweakForDeformer;
            }
            
            mesh.triangulate(lineForTri, 28, -1);
            
            for (auto& v: mesh.triangulatedMesh.getVertices())
            {
                mesh.triangulatedMesh.addTexCoord(tex.getCoordFromPoint(v.x + tweakForDeformer.x,
                                                                        v.y + tweakForDeformer.y));
            }
            
            instance.setup(mesh.triangulatedMesh, lineForTri);
            
            vector<ofPoint> pts = line.getVertices();

            b2dObj = ofPtr<ofxBox2dPolygon>(new ofxBox2dPolygon);
            b2dObj->addVertices(pts);
            b2dObj->setPhysics(1.0, 0.3, 0.3);
            b2dObj->triangulatePoly();
            b2dObj->create(Globals::box2d->getWorld());
            b2dObj->setPosition(pos);
        }
    }
}
示例#19
0
//----------------------------------------------------------
void of3dPrimitive::mapTexCoordsFromTexture( ofTexture& inTexture ) {
    bool bNormalized = true;
#ifndef TARGET_OPENGLES
    bNormalized = (inTexture.getTextureData().textureTarget!=GL_TEXTURE_RECTANGLE_ARB);
#endif
    
    ofTextureData& tdata = inTexture.getTextureData();
    if(bNormalized)
        mapTexCoords( 0, 0, tdata.tex_t, tdata.tex_u );
    else
        mapTexCoords(0, 0, inTexture.getWidth(), inTexture.getHeight());
    
    ofVec4f tcoords = getTexCoords();
    mapTexCoords(tcoords.x, tcoords.y, tcoords.z, tcoords.w);
}
示例#20
0
void Clone::debugShader(ofTexture &tex, ofTexture &mask){

    debugFbo.allocate(buffer.getWidth(), buffer.getHeight());
    debugResultFbo.allocate(buffer.getWidth(), buffer.getHeight());
    ofShader debugShader;
    debugShader.load("shader/maskBlurShader");
    
    setStrength(16);
    

    debugFbo.begin();
    
//    debugShader.begin();
//    
//    //maskBlurShader.setUniformTexture("tex", tex, 1);
//    debugShader.setUniformTexture("tex0", tex, 1);
//    debugShader.setUniformTexture("mask", mask, 2);
//    debugShader.setUniform2f("direction", 0, 1);
//    debugShader.setUniform1i("k", strength);
//    mask.draw(0, 0);
//    
//    debugShader.end();
    maskBlurShader.begin();
    maskBlurShader.setUniformTexture("tex0", tex, 1);
    maskBlurShader.setUniformTexture("mask", mask, 2);
    //maskBlurShader.setUniform2f("direction", 0., 1./tex.getHeight());
    maskBlurShader.setUniform2f("direction", 1./tex.getWidth(), 0.);
    maskBlurShader.setUniform1i("k", strength);
    tex.draw(0, 0);
    maskBlurShader.end();
    
    
    debugFbo.end();
    
//    debugResultFbo.begin();
//    
//    maskBlurShader.setUniformTexture("tex0", debugFbo, 1);
//    maskBlurShader.setUniformTexture("mask", mask, 2);
//    maskBlurShader.setUniform2f("direction", 0., 1./tex.getHeight());
//    maskBlurShader.setUniform1i("k", strength);
//    debugFbo.draw(0, 0);
//    
//    debugResultFbo.end();
    
    
}
void dpMarionette::drawShoulderPoint(ofTexture &tex,
									 const ramNode &nodeA,
									 const ramNode &nodeB,
									 const ramNode &nodeC,int width, int resolution){
	//A is NECK!
	ofNode parent[3];
	parent[0] = nodeA;
	parent[1] = nodeB;
	parent[2] = nodeC;

	ofNode child[4];
	child[0].setParent(parent[0]);
	child[1].setParent(parent[0]);
	child[2].setParent(parent[1]);
	child[3].setParent(parent[2]);

	child[0].setPosition( width/2.0, 0.0, 0.0);
	child[1].setPosition(-width/2.0, 0.0, 0.0);

	child[2].setPosition( 12.0, 0.0, 0.0);
	child[3].setPosition(-12.0, 0.0, 0.0);

	ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight());
	ofVec3f targA,targB;
	float sliceP;

	tex.bind();
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0;i < resolution + 1;i++){
		sliceP = i/float(resolution);
		targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(),
														  sliceP);
		targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(),
														  sliceP);

		glTexCoord2d(0.0, texSize.y * sliceP);
		glVertex3d(targA.x, targA.y, targA.z);
		glTexCoord2d(texSize.x, texSize.y * sliceP);
		glVertex3d(targB.x, targB.y, targB.z);

	}
	glEnd();
	tex.unbind();
}
void CloudsVisualSystemMemory::generateFromTexture(ofTexture &_tex){

    ofPixels pixels;
    _tex.readToPixels(pixels);
    
    int xMargin = 20;
    int yMargin = 20;
    
    int width = ofGetWidth()-xMargin*2.0;
    int height = ofGetHeight()-yMargin*2.0;
    
    ofRectangle block;
    block.width = blockWidth*blockScale;
    block.height = blockHeight*blockScale;
    
    xBlocks = (float)width/((blockWidth+margin)*blockScale);
    yBlocks = (float)height/((blockHeight+margin)*blockScale);
    
    blocks.clear();
    for (int j = 0; j < yBlocks; j++) {
        for (int i = 0; i < xBlocks; i++){
            
            int x = xMargin + ((margin + blockWidth)*blockScale)*i ;
            int y = yMargin + ((margin + blockHeight)*blockScale)*j ;
            
            Block newBlock;
            newBlock.set(block);
            newBlock.x = x+block.width*0.5;
            newBlock.y = y+block.height*0.5;
            
            ofPoint st = ofPoint( ((float)i)/((float)xBlocks), ((float)j)/((float)yBlocks));
            st *= ofPoint(_tex.getWidth(),_tex.getHeight());
            
            newBlock.value = pixels.getColor( st.x, st.y ).r;//.getBrightness() ;
            newBlock.color = ofColor( newBlock.value );
            newBlock.borderColor = borderColor;
            newBlock.bSelected = false;
            
            blocks.push_back(newBlock);
        }
    }
}
示例#23
0
void ofxParticle::draw(ofTexture &tex){
    float w = tex.getWidth();
    float h = tex.getHeight();
    if(w > h){
        h = h/w*size;
        w = size;
    }
    else{
        w = w/h*size;
        h = size;
    }
    ofSetColor(color);
    ofPushMatrix();
    ofTranslate(position);
    ofRotateX(rotation.x);
    ofRotateY(rotation.y);
    ofRotateZ(rotation.z);
    tex.draw(w*-0.5,h*-0.5,w,h);
    ofPopMatrix();
}
示例#24
0
	//----------
	bool Receiver::receive(ofTexture & texture) {
		try {
			//check if we're initialised
			if (!this->isInitialized()) {
				throw("Not initialized");
			}

			//prepare the channel name, allow it to be changed if different channels are available
			char mutableName[256];
			unsigned int mutableWidth, mutableHeight;
			strcpy_s(mutableName, this->channelName.size() + 1, this->channelName.c_str());

			//check if the texture is allocated correctly, if not, allocate it
			if (texture.getWidth() != this->width || texture.getHeight() != this->height) {
				int format = texture.isAllocated() ? texture.getTextureData().glInternalFormat : this->defaultFormat;
				texture.allocate(width, height, format);
			}

			//pull data into the texture (keep any existing fbo attachments)
			GLint drawFboId = 0;
			glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
			if (!this->spoutReceiver->ReceiveTexture(mutableName, mutableWidth, mutableHeight, texture.getTextureData().textureID, texture.getTextureData().textureTarget, false, drawFboId)) {
				throw("Can't receive texture");
			}

			//update our local settings incase anything changed
			this->channelName = mutableName;
			this->width = mutableWidth;
			this->height = mutableHeight;

			return true;
		}
		catch (const char * e) {
			ofLogError("ofxSpout::Receiver::receive") << e;
			return false;
		}
	}
示例#25
0
文件: ofxPBO.cpp 项目: alg-a/GAmuza
void ofxPBO::allocate(ofTexture & tex, int numPBOs){
	pboIds.resize(numPBOs);
    glGenBuffersARB(numPBOs, &pboIds[0]);
    int numChannels=1;
    switch(tex.getTextureData().glTypeInternal){
        case GL_LUMINANCE:
            numChannels = 1;
            break;
        case GL_RGB:
            numChannels = 3;
            break;
        case GL_RGBA:
            numChannels = 4;
            break;
    }
    dataSize = tex.getWidth()*tex.getHeight()*numChannels;
    for(int i=0;i<(int)pboIds.size();i++){
		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[i]);
		glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, dataSize, 0, GL_STREAM_DRAW_ARB);
    }
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
    
    texture = tex;
}
示例#26
0
void Clone::maskedBlur(ofTexture& tex, ofTexture& mask, ofFbo& result) {
    int k = strength;
    
    buffer.begin();
    maskBlurShader.begin();
    maskBlurShader.setUniformTexture("tex0", tex, 1);
    maskBlurShader.setUniformTexture("mask", mask, 2);
    maskBlurShader.setUniform2f("direction", 1./(tex.getWidth()*2), 0.);
    maskBlurShader.setUniform1i("k", k);
    tex.draw(0, 0);
    maskBlurShader.end();
    buffer.end();

    result.begin();
    maskBlurShader.begin();
    maskBlurShader.setUniformTexture("tex0", buffer, 1);
    maskBlurShader.setUniformTexture("mask", mask, 2);
    maskBlurShader.setUniform2f("direction", 0., 1./(buffer.getHeight()));
    maskBlurShader.setUniform1i("k", k);
    buffer.draw(0, 0);
    maskBlurShader.end();
    buffer.draw(0, 0);
    result.end();
}
void dpMarionette::drawElbowPoint(ofTexture &tex, const ramNode &nodeA, const ramNode &nodeB, const ramNode &nodeC, int width, int resolution, bool isLEFT){

	ofNode parent[3];
	parent[0] = nodeA;
	parent[1] = nodeB;
	parent[2] = nodeC;

	ofNode subParent[2];
	subParent[0].setParent(parent[1]);
	subParent[1].setParent(parent[2]);

	if (isLEFT){
		subParent[0].setPosition(-12.0, 0.0, 0.0);
		subParent[1].setPosition( 12.0, 0.0, 0.0);
	}else{
		subParent[0].setPosition( 12.0, 0.0, 0.0);
		subParent[1].setPosition(-12.0, 0.0, 0.0);
	}

	ofNode child[4];
	child[0].setParent(parent[0]);
	child[1].setParent(parent[0]);

	if (isLEFT){
		child[2].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.0));
		child[3].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.2));
	}else{
		child[2].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.2));
		child[3].setGlobalPosition(subParent[1].getGlobalPosition().
								   interpolate(subParent[0].getGlobalPosition(), 0.0));
	}

	child[0].setPosition( width/2.0, 0.0, 0.0);
	child[1].setPosition(-width/2.0, 0.0, 0.0);



	ofVec2f texSize = ofVec2f(tex.getWidth(),tex.getHeight());
	ofVec3f targA,targB;
	float sliceP;

	tex.bind();
	glBegin(GL_TRIANGLE_STRIP);
	for (int i = 0;i < resolution + 1;i++){
		sliceP = i/float(resolution);
		targA = child[0].getGlobalPosition().interpolated(child[2].getGlobalPosition(),
														  sliceP);
		targB = child[1].getGlobalPosition().interpolated(child[3].getGlobalPosition(),
														  sliceP);

		glTexCoord2d(0.0, texSize.y * (1.0 - sliceP));
		glVertex3d(targA.x, targA.y, targA.z);
		glTexCoord2d(texSize.x, texSize.y * (1.0 - sliceP));
		glVertex3d(targB.x, targB.y, targB.z);

	}
	glEnd();
	tex.unbind();

	ofVec3f guideA = subParent[0].getGlobalPosition().interpolate(subParent[1].getGlobalPosition(),
																  5.0);
	ofVec3f guideB = subParent[1].getGlobalPosition().interpolate(subParent[0].getGlobalPosition(),
																  5.0);

}
示例#28
0
//--------------------------------------------------------------
void ofPlanePrimitive::resizeToTexture( ofTexture& inTexture, float scale ) {
    set(inTexture.getWidth() * scale, inTexture.getHeight() * scale);
    mapTexCoordsFromTexture( inTexture );
}
示例#29
0
//--------------------------------------------------------------
void ofBoxPrimitive::resizeToTexture( ofTexture& inTexture ) {
    set(inTexture.getWidth(), inTexture.getHeight(), inTexture.getWidth());
    mapTexCoordsFromTexture( inTexture );
}
示例#30
0
//--------------------------------------------------------------
void Sender::sendTexture(ofTexture& t, string name)
{
	int width = t.getWidth();
	int height = t.getHeight();

	//lookup the sender
	int i = ofFind(senderNameList, name); 

	//if the sender is not there
	if (i == senderNameList.size()) {
		char senderNameChars[256];
		strcpy_s(senderNameChars, name.c_str());
		SpoutSender* sender = new SpoutSender();
		bool init = sender->CreateSender(senderNameChars, width, height);
	
		if (init) {
			ofLogNotice("ofxSpout2 Sender created");
			//init the fbo
			ofFbo senderFbo;
			ofFbo::Settings s;
			s.width = width;
			s.height = height;
			s.internalformat = GL_RGBA;
			s.textureTarget = GL_TEXTURE_2D;
			s.useDepth = false;
			s.useStencil = false;
			s.minFilter = GL_LINEAR;
			s.maxFilter = GL_LINEAR;
			s.wrapModeHorizontal = GL_CLAMP_TO_EDGE;
			s.wrapModeVertical = GL_CLAMP_TO_EDGE;
			s.numSamples = 0;
			senderFbo.allocate(s);
			senderFboList.push_back(senderFbo);
			senderWidthList.push_back(width);
			senderHeightList.push_back(height);
			senderNameList.push_back(name);
			spoutSenderList.push_back(sender);
		} else {
			ofLogError("ofxSpout2 Sender creation failed");
		}
		//we cannot create sender and immediatly send texture; so return
		return;
	}


	if (i >= 0 && i < senderNameList.size())
	{	
		if ((width != senderWidthList[i]) || (height != senderHeightList[i])) {
			// quick and dirty fix for spoutSender ignoring texture resolution changes
			senderFboList[i].destroy();
			ofFbo senderFbo;
			ofFbo::Settings s;
			s.width = width;
			s.height = height;
			s.internalformat = GL_RGBA;
			s.textureTarget = GL_TEXTURE_2D;
			s.useDepth = false;
			s.useStencil = false;
			s.minFilter = GL_LINEAR;
			s.maxFilter = GL_LINEAR;
			s.wrapModeHorizontal = GL_CLAMP_TO_EDGE;
			s.wrapModeVertical = GL_CLAMP_TO_EDGE;
			s.numSamples = 0;
			senderFbo.allocate(s);
			senderFboList[i] = senderFbo;
			senderWidthList[i] = width;
			senderHeightList[i] = height;
		}
		ofPushMatrix();
		ofPushStyle();
		senderFboList[i].begin();
		ofClear(0);
		ofSetColor(255);
		t.draw(0,0,width,height);
		senderFboList[i].end();
		ofPopStyle();
		ofPopMatrix();
		glBindTexture(GL_TEXTURE_2D, 0);  //
		spoutSenderList[i]->SendTexture(senderFboList[i].getTextureReference().getTextureData().textureID, GL_TEXTURE_2D, senderWidthList[i], senderHeightList[i], false); 
	}
}