void CloudsVisualSystemMemory::generateFromTexture(ofTexture &_tex){

    ofPixels pixels;
    _tex.readToPixels(pixels);
    
    
    int xMargin = 0;
    int yMargin = 0;
    
    //MA: changed ofGetWidth() to getCanvasWidth() and ofGetHeight() to getCanvasHeight()
    int width = getCanvasWidth()-xMargin*2.0;
    int height = getCanvasHeight()-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);
    
	outlineMesh.clear();
	outlineMesh.setMode(OF_PRIMITIVE_LINES);
	outlineMesh.setUsage(GL_STREAM_DRAW);
	
	fillMesh.clear();
	fillMesh.setMode(OF_PRIMITIVE_TRIANGLES);
	outlineMesh.setUsage(GL_STATIC_DRAW);

    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 = xMargin + ((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 ).getBrightness();
//            newBlock.color = ofColor( newBlock.value)/brightnessOffset;
			if(baseColorRange.min == baseColorRange.max){
				newBlock.color = ofFloatColor(baseColorRange.min);
			}
			else{
				newBlock.color = ofFloatColor(ofMap(newBlock.value, 0, 255,
													baseColorRange.min,baseColorRange.max), 1.0);
			}
			newBlock.borderBase = borderBase;
            newBlock.borderColor = borderColor;
            newBlock.bSelected = false;
            
			newBlock.outlineMesh = &outlineMesh;
			newBlock.fillMesh = &fillMesh;
			newBlock.setup();

            blocks.push_back(newBlock);
        }
    }
}
TiltShiftFilter::TiltShiftFilter(ofTexture & texture, float focusPercent, float falloff) : AbstractFilter(texture.getWidth(), texture.getHeight()) {
    _name = "Tilt Shift";
    _texture = texture;
    _focusPercent=ofClamp(focusPercent, 0, 1);
    _gaussianBlurFilter = new GaussianBlurFilter(getWidth(), getHeight());
    _addParameter(new ParameterF("topFocusLevel", focusPercent));
    _addParameter(new ParameterF("bottomFocusLevel", 1.f - focusPercent));
    _addParameter(new ParameterF("focusFallOffRate", falloff));
    _addParameter(new ParameterT("inputImageTexture", _texture, 1));
    _addParameter(new ParameterT("inputImageTexture2", _gaussianBlurFilter->getTextureReference(), 2));
    _setupShader();
}
MotionDetectionFilter::MotionDetectionFilter(ofTexture & texture, float intensity, bool showImage) : AbstractTwoInputFilter(texture.getWidth(), texture.getHeight()) {
    _name = "Motion Detection";
    _texture = texture;
    _lowPassFilter = new LowPassFilter(getWidth(), getHeight(), 0.6);
    setSecondTexture(_lowPassFilter->getTextureReference());
    _addParameter(new ParameterF("intensity", intensity));
    _addParameter(new ParameterF("showImage", (float)showImage));
    _setupShader();
}
示例#4
0
//--------------------------------------------------------------
void ofPlanePrimitive::resizeToTexture( ofTexture& inTexture, float scale ) {
    set(inTexture.getWidth() * scale, inTexture.getHeight() * scale);
    mapTexCoordsFromTexture( inTexture );
}
示例#5
0
//--------------------------------------------------------------
void ofBoxPrimitive::resizeToTexture( ofTexture& inTexture ) {
    set(inTexture.getWidth(), inTexture.getHeight(), inTexture.getWidth());
    mapTexCoordsFromTexture( inTexture );
}
void EasyMask::drawMask ( ofTexture contentTex , ofTexture maskTex , float xOffset , float yOffset , float contentAlpha )
{
    /*
    if ( contentTex.getWidth() < maskArea.width )
        maskArea.width = contentTex.getWidth() ;
    if ( contentTex.getHeight() < maskArea.height )
        maskArea.height = contentTex.getHeight() ;
    */
    //TEX0 = CONTENT
    //TEX1 = M

    //BEGIN MASK
    ofEnableAlphaBlending( ) ;
	//ofSetColor ( 255 , 255 , 255 ) ;
      //  contentTex.setTextureWrap( GL_CLAMP, GL_CLAMP ) ;

		glActiveTexture(GL_TEXTURE0_ARB);
		contentTex.bind();

		glActiveTexture(GL_TEXTURE1_ARB);
		maskTex.bind();

            //prevents weird texture wrapping
           // contentTex.setTextureWrap( GL_CLAMP_TO_BORDER_ARB, GL_CLAMP_TO_BORDER_ARB ) ;
            contentTex.setTextureWrap( GL_CLAMP_TO_BORDER_ARB , GL_CLAMP_TO_BORDER_ARB ) ;
          //  texture1.setTextureWrap( GL_CLAMP , GL_CLAMP ) ;

            //xOffset = sin ( ofGetElapsedTimef() ) * 500.0f ;
            maskShader.begin();

                maskShader.setUniformTexture("Tex0", contentTex , 0);
                maskShader.setUniformTexture("Tex1", maskTex , 1);
                maskShader.setUniform1f( "alpha" , contentAlpha ) ;
                glBegin(GL_QUADS);
                ofFill() ;
              //  ofSetColor ( 255 , 255 , 255 , 255 ) ;

              //  maskOffset = 0 ; //sin ( ofGetElapsedTimef() ) * 200.0f ;
                glMultiTexCoord2d(GL_TEXTURE0_ARB, xOffset , yOffset );
                glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, contentAlpha );
                glVertex2f( maskArea.x ,  maskArea.y );


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


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

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

                glEnd();

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

		glActiveTexture(GL_TEXTURE0_ARB);
		contentTex.unbind();

		//maskArea = originalMaskArea ;
}