Example #1
0
void AlphaMask::draw(){
    ofApp *app = ((ofApp*)ofGetAppPtr());
    srcTex = app->blackmagic->colorTexture;
    
    fbo.begin();
    ofClear(0, 0, 0);
    maskShader.begin();
    
    glActiveTexture(GL_TEXTURE0_ARB);
    srcTex.bind();
    
    glActiveTexture(GL_TEXTURE1_ARB);
    mask.getTextureReference().bind();
    
    glBegin(GL_QUADS);
    
    float maskOffsetX =  ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getWidth(), mask.getWidth() / 3.0);
    float maskOffsetY =  ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getHeight(), mask.getHeight() / 3.0);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, maskOffsetY);
    glVertex2f(0, 0);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), 0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, maskOffsetY);
    glVertex2f(1920, 0);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), srcTex.getHeight());
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, mask.getHeight() - maskOffsetY);
    glVertex2f( 1920, 1080);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, srcTex.getHeight());
    glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, mask.getHeight() - maskOffsetY);
    glVertex2f(0, 1080);
    
    glEnd();
    
    glActiveTexture(GL_TEXTURE1_ARB);
    mask.getTextureReference().unbind();
    
    glActiveTexture(GL_TEXTURE0_ARB);
    srcTex.unbind();
    
    maskShader.end();
    fbo.end();
    
    ofSetColor(255, app->oscControl->controlVal[2] * 2);
    fbo.draw(0, 0);
    
    if (app->screenMode == 0) {
        ofSetColor(0);
        ofSetRectMode(OF_RECTMODE_CORNER);
        ofPushMatrix();
        ofRect(0, 0, 1920, 224);
        ofTranslate(0, 630 + 224);
        ofRect(0, 0, 1920, 300);
        ofPopMatrix();
    }
}
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 ;
}
Example #3
0
void Face::display() {
    Vert *v1 = edge->vert,
         *v2 = edge->next->vert,
         *v3 = edge->prev->vert;

    Vector tangent_1_2 = ((v2->point - v1->point) - (v2->point - v1->point).dot(v1->normal()) * v1->normal());
    Vector tangent_1_3 = ((v3->point - v1->point) - (v3->point - v1->point).dot(v1->normal()) * v1->normal());
    Vector tangent_2_1 = ((v1->point - v2->point) - (v1->point - v2->point).dot(v2->normal()) * v2->normal());
    Vector tangent_2_3 = ((v3->point - v2->point) - (v3->point - v2->point).dot(v2->normal()) * v2->normal());
    Vector tangent_3_1 = ((v1->point - v3->point) - (v1->point - v3->point).dot(v3->normal()) * v3->normal());
    Vector tangent_3_2 = ((v2->point - v3->point) - (v2->point - v3->point).dot(v3->normal()) * v3->normal());

    double dist_1_2_x = tangent_1_2.dot(v1->max_curvature_dir().unit()),
           dist_1_2_y = tangent_1_2.dot(v1->max_curvature_dir().cross(v1->normal()).unit()),
           dist_1_3_x = tangent_1_3.dot(v1->max_curvature_dir().unit()),
           dist_1_3_y = tangent_1_3.dot(v1->max_curvature_dir().cross(v1->normal()).unit());

    double dist_2_1_x = tangent_2_1.dot(v2->max_curvature_dir().unit()),
           dist_2_1_y = tangent_2_1.dot(v2->max_curvature_dir().cross(v2->normal()).unit()),
           dist_2_3_x = tangent_2_3.dot(v2->max_curvature_dir().unit()),
           dist_2_3_y = tangent_2_3.dot(v2->max_curvature_dir().cross(v2->normal()).unit());

    double dist_3_1_x = tangent_3_1.dot(v3->max_curvature_dir().unit()),
           dist_3_1_y = tangent_3_1.dot(v3->max_curvature_dir().cross(v3->normal()).unit()),
           dist_3_2_x = tangent_3_2.dot(v3->max_curvature_dir().unit()),
           dist_3_2_y = tangent_3_2.dot(v3->max_curvature_dir().cross(v3->normal()).unit());

    glMultiTexCoord2d(GL_TEXTURE0, 0.0, 0.0);
    glMultiTexCoord2d(GL_TEXTURE1, SCALE * dist_2_1_x, SCALE * dist_2_1_y);
    glMultiTexCoord2d(GL_TEXTURE2, SCALE * dist_3_1_x, SCALE * dist_3_1_y);

    glNormal3d(v1->normal().dx, v1->normal().dy, v1->normal().dz);
    glVertex3d(v1->point.x, v1->point.y, v1->point.z);

    glMultiTexCoord2d(GL_TEXTURE0, SCALE * dist_1_2_x, SCALE * dist_1_2_y);
    glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0);
    glMultiTexCoord2d(GL_TEXTURE2, SCALE * dist_3_2_x, SCALE * dist_3_2_y);

    glNormal3d(v2->normal().dx, v2->normal().dy, v2->normal().dz);
    glVertex3d(v2->point.x, v2->point.y, v2->point.z);

    glMultiTexCoord2d(GL_TEXTURE0, SCALE * dist_1_3_x, SCALE * dist_1_3_y);
    glMultiTexCoord2d(GL_TEXTURE1, SCALE * dist_2_3_x, SCALE * dist_2_3_y);
    glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0);

    glNormal3d(v3->normal().dx, v3->normal().dy, v3->normal().dz);
    glVertex3d(v3->point.x, v3->point.y, v3->point.z);
}
void TextImageContent::draw ( )
{
    ofSetColor ( 255 , 255 , 255 ) ;

    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);
	image.getTextureReference().bind();

	glActiveTexture(GL_TEXTURE1_ARB);
	mask.getTextureReference().bind();

	//draw a quad the size of the frame
	glBegin(GL_QUADS);
	ofFill() ;
	ofSetColor ( 255 , 255 , 255 , 255 ) ;

	float maskOffset = -scroll.y ; //15 - mouseY;	/*
	glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, maskOffset);
	glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 0);
	glVertex2f( bounds.x, bounds.y );

	glMultiTexCoord2d(GL_TEXTURE0_ARB, image.getWidth(), maskOffset);
	glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth(), 0);
	glVertex2f( bounds.x + bounds.width , bounds.y );

	glMultiTexCoord2d(GL_TEXTURE0_ARB, image.getWidth(), mask.getHeight() + maskOffset );
	glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth(), mask.getHeight() );
	glVertex2f( bounds.x + bounds.width , bounds.y + bounds.height );

	glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, mask.getHeight() + maskOffset );
	glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, mask.getHeight() );
	glVertex2f( bounds.x , bounds.y + bounds.height );

	glEnd() ;

	//deactive and clean up
	glActiveTexture(GL_TEXTURE1_ARB);
	mask.getTextureReference().unbind();

	glActiveTexture(GL_TEXTURE0_ARB);
	image.getTextureReference().unbind();

    maskShader.end();

    //draw scrollbar indicator
    ofEnableAlphaBlending() ;
    ofSetColor ( 15 , 15 , 15 , 200 ) ;
    roundedRect ( bounds.x + bounds.width + 5 , bounds.y + (-scroll.y *.85) , 4 , 40 , 5 ) ;
}
Example #5
0
	void post_process(
			const safe_ptr<device_buffer>& background, bool straighten_alpha)
	{
		bool should_post_process = 
				supports_texture_barrier_
				&& straighten_alpha
				&& post_processing_;

		if (!should_post_process)
			return;

		if (!blend_modes_)
			ogl_->disable(GL_BLEND);

		ogl_->disable(GL_POLYGON_STIPPLE);

		ogl_->attach(*background);

		background->bind(texture_id::background);

		ogl_->use(*shader_);
		shader_->set("background", texture_id::background);
		shader_->set("post_processing", should_post_process);
		shader_->set("straighten_alpha", straighten_alpha);

		ogl_->viewport(0, 0, background->width(), background->height());

		glBegin(GL_QUADS);
			glMultiTexCoord2d(GL_TEXTURE0, 0.0, 0.0); glVertex2d(-1.0, -1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 1.0, 0.0); glVertex2d( 1.0, -1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 1.0, 1.0); glVertex2d( 1.0,  1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 0.0, 1.0); glVertex2d(-1.0,  1.0);
		glEnd();

		glTextureBarrierNV();

		if (!blend_modes_)
			ogl_->enable(GL_BLEND);
	}
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();
}
Example #7
0
void nRenderer::drawVertex(nVertex vert) {
	#ifndef N_MULTI_TEX_COORD
		glMultiTexCoord2d(GL_TEXTURE0, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE1, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE2, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE3, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE4, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE5, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE6, vert.coords.x, vert.coords.y);
		glMultiTexCoord2d(GL_TEXTURE7, vert.coords.x, vert.coords.y);
	#else
		TO DO !
	#endif
	glNormal3d(vert.normal.x, vert.normal.y, vert.normal.z);
	glVertex3d(vert.position.x, vert.position.y, vert.position.z);
}
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() ;
}
//--------------------------------------------------------------
void testApp::draw(){
	

	//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);
	movie.getTextureReference().bind();


	//draw a quad the size of the frame
	glBegin(GL_QUADS);
	
	//move the mask around with the mouse by modifying the texture coordinates
	glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);
	glVertex2f( 0, 0);

	glMultiTexCoord2d(GL_TEXTURE0_ARB, movie.getWidth(), 0);
	glVertex2f( ofGetWidth(), 0);

	glMultiTexCoord2d(GL_TEXTURE0_ARB, movie.getWidth(), movie.getHeight());
	glVertex2f( ofGetWidth(), ofGetHeight());

	glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, movie.getHeight());
	glVertex2f( 0, ofGetHeight() );
	
	glEnd();
	
	//deactive and clean up
	glActiveTexture(GL_TEXTURE0_ARB);
	movie.getTextureReference().unbind();
	
	
	maskShader.end();
}
Example #10
0
	void draw(draw_params&& params)
	{
		static const double epsilon = 0.001;

		CASPAR_ASSERT(params.pix_desc.planes.size() == params.textures.size());

		if(params.textures.empty() || !params.background)
			return;

		if(params.transform.opacity < epsilon)
			return;
		
		if(!std::all_of(params.textures.begin(), params.textures.end(), std::mem_fn(&device_buffer::ready)))
		{
			CASPAR_LOG(trace) << L"[image_mixer] Performance warning. Host to device transfer not complete, GPU will be stalled";
			ogl_->yield(); // Try to give it some more time.
		}		
		
		// Bind textures

		for(size_t n = 0; n < params.textures.size(); ++n)
			params.textures[n]->bind(n);

		if(params.local_key)
			params.local_key->bind(texture_id::local_key);
		
		if(params.layer_key)
			params.layer_key->bind(texture_id::layer_key);
			
		// Setup shader
								
		ogl_->use(*shader_);

		shader_->set("plane[0]",		texture_id::plane0);
		shader_->set("plane[1]",		texture_id::plane1);
		shader_->set("plane[2]",		texture_id::plane2);
		shader_->set("plane[3]",		texture_id::plane3);
		shader_->set("local_key",		texture_id::local_key);
		shader_->set("layer_key",		texture_id::layer_key);
		shader_->set("is_hd",		 	params.pix_desc.planes.at(0).height > 700 ? 1 : 0);
		shader_->set("has_local_key",	bool(params.local_key));
		shader_->set("has_layer_key",	bool(params.layer_key));
		shader_->set("pixel_format",	params.pix_desc.pix_fmt);	
		shader_->set("opacity",			params.transform.is_key ? 1.0 : params.transform.opacity);	
		shader_->set("post_processing",	false);

		shader_->set("chroma_mode",    params.blend_mode.chroma.key == chroma::green ? 1 : (params.blend_mode.chroma.key == chroma::blue ? 2 : 0));
        shader_->set("chroma_blend",   params.blend_mode.chroma.threshold, params.blend_mode.chroma.softness);
        shader_->set("chroma_spill",   params.blend_mode.chroma.spill);
//        shader_->set("chroma.key",      ((params.blend_mode.chroma.key >> 24) && 0xff)/255.0f,
//                                        ((params.blend_mode.chroma.key >> 16) && 0xff)/255.0f,
//                                        (params.blend_mode.chroma.key & 0xff)/255.0f);
//		if (params.blend_mode.chroma.key != chroma::none)
//		{
//		    shader_->set("chroma.threshold", 	params.blend_mode.chroma.threshold);
//		    shader_->set("chroma.softness",     params.blend_mode.chroma.softness);
//            shader_->set("chroma.blur",         params.blend_mode.chroma.blur);
//		    shader_->set("chroma.spill",        params.blend_mode.chroma.spill);
//            shader_->set("chroma.show_mask",    params.blend_mode.chroma.show_mask);
//		}
		
		// Setup blend_func		
		if(params.transform.is_key)
			params.blend_mode = blend_mode::normal;

		if(blend_modes_)
		{
			params.background->bind(texture_id::background);

			shader_->set("background",	texture_id::background);
			shader_->set("blend_mode",	params.blend_mode.mode);
			shader_->set("keyer",		params.keyer);
		}
		else
		{
			switch(params.keyer)
			{
			case keyer::additive:
				ogl_->blend_func(GL_ONE, GL_ONE);	
				break;
			case keyer::linear:
			default:				
				ogl_->blend_func(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);	
			}		
		}

		// Setup image-adjustements
		
		if(params.transform.levels.min_input  > epsilon		||
		   params.transform.levels.max_input  < 1.0-epsilon	||
		   params.transform.levels.min_output > epsilon		||
		   params.transform.levels.max_output < 1.0-epsilon	||
		   std::abs(params.transform.levels.gamma - 1.0) > epsilon)
		{
			shader_->set("levels", true);	
			shader_->set("min_input",	params.transform.levels.min_input);	
			shader_->set("max_input",	params.transform.levels.max_input);
			shader_->set("min_output",	params.transform.levels.min_output);
			shader_->set("max_output",	params.transform.levels.max_output);
			shader_->set("gamma",		params.transform.levels.gamma);
		}
		else
			shader_->set("levels", false);	

		if(std::abs(params.transform.brightness - 1.0) > epsilon ||
		   std::abs(params.transform.saturation - 1.0) > epsilon ||
		   std::abs(params.transform.contrast - 1.0)   > epsilon)
		{
			shader_->set("csb",	true);	
			
			shader_->set("brt", params.transform.brightness);	
			shader_->set("sat", params.transform.saturation);
			shader_->set("con", params.transform.contrast);
		}
		else
			shader_->set("csb",	false);	
		
		// Setup interlacing

		if(params.transform.field_mode == core::field_mode::progressive)			
			ogl_->disable(GL_POLYGON_STIPPLE);			
		else			
		{
			ogl_->enable(GL_POLYGON_STIPPLE);

			if(params.transform.field_mode == core::field_mode::upper)
				ogl_->stipple_pattern(upper_pattern);
			else if(params.transform.field_mode == core::field_mode::lower)
				ogl_->stipple_pattern(lower_pattern);
		}

		// Setup drawing area
		
		ogl_->viewport(0, 0, params.background->width(), params.background->height());
								
		auto m_p = params.transform.clip_translation;
		auto m_s = params.transform.clip_scale;

		bool scissor = m_p[0] > std::numeric_limits<double>::epsilon()			|| m_p[1] > std::numeric_limits<double>::epsilon() ||
					   m_s[0] < (1.0 - std::numeric_limits<double>::epsilon())	|| m_s[1] < (1.0 - std::numeric_limits<double>::epsilon());

		if(scissor)
		{
			double w = static_cast<double>(params.background->width());
			double h = static_cast<double>(params.background->height());
		
			ogl_->enable(GL_SCISSOR_TEST);
			ogl_->scissor(static_cast<size_t>(m_p[0]*w), static_cast<size_t>(m_p[1]*h), static_cast<size_t>(m_s[0]*w), static_cast<size_t>(m_s[1]*h));
		}

		auto f_p = params.transform.fill_translation;
		auto f_s = params.transform.fill_scale;
		
		// Set render target
		
		ogl_->attach(*params.background);
		
		// Draw
				
		/*
			GL_TEXTURE0 are texture coordinates to the source material, what will be rendered with this call. These are always set to the whole thing.
			GL_TEXTURE1 are texture coordinates to background- / key-material, that which will have to be taken in consideration when blending. These are set to the rectangle over which the source will be rendered
		*/
		glBegin(GL_QUADS);
			glMultiTexCoord2d(GL_TEXTURE0, 0.0, 0.0); glMultiTexCoord2d(GL_TEXTURE1,  f_p[0]        ,  f_p[1]        );		glVertex2d( f_p[0]        *2.0-1.0,  f_p[1]        *2.0-1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 1.0, 0.0); glMultiTexCoord2d(GL_TEXTURE1, (f_p[0]+f_s[0]),  f_p[1]        );		glVertex2d((f_p[0]+f_s[0])*2.0-1.0,  f_p[1]        *2.0-1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 1.0, 1.0); glMultiTexCoord2d(GL_TEXTURE1, (f_p[0]+f_s[0]), (f_p[1]+f_s[1]));		glVertex2d((f_p[0]+f_s[0])*2.0-1.0, (f_p[1]+f_s[1])*2.0-1.0);
			glMultiTexCoord2d(GL_TEXTURE0, 0.0, 1.0); glMultiTexCoord2d(GL_TEXTURE1,  f_p[0]        , (f_p[1]+f_s[1]));		glVertex2d( f_p[0]        *2.0-1.0, (f_p[1]+f_s[1])*2.0-1.0);
		glEnd();
		
		// Cleanup

		ogl_->disable(GL_SCISSOR_TEST);	
						
		params.textures.clear();
		ogl_->yield(); // Return resources to pool as early as possible.

		if(blend_modes_)
		{
			// http://www.opengl.org/registry/specs/NV/texture_barrier.txt
			// This allows us to use framebuffer (background) both as source and target while blending.
			glTextureBarrierNV(); 
		}
	}
Example #11
0
File: ogl.cpp Project: keithw/ahab
void OpcodeState::paint( void )
{
  glPushMatrix();
  glLoadIdentity();
  glTranslatef( 0, 0, 0 );
  glBegin( GL_POLYGON );

  const double ff = 1.0/128; /* Mesa fudge factor */
  const double xoffset = 0.25; /* MPEG-2 style 4:2:0 subsampling */

  glMultiTexCoord2d( GL_TEXTURE0, ff, ff );
  glMultiTexCoord2d( GL_TEXTURE1, xoffset+ff, ff );
  glMultiTexCoord2d( GL_TEXTURE2, xoffset+ff, ff );
  glVertex2s( 0, 0 );

  glMultiTexCoord2d( GL_TEXTURE0, dispwidth+ff, ff );
  glMultiTexCoord2d( GL_TEXTURE1, dispwidth/2 + xoffset + ff, ff );
  glMultiTexCoord2d( GL_TEXTURE2, dispwidth/2 + xoffset + ff, ff );
  glVertex2s( width, 0 );

  glMultiTexCoord2d( GL_TEXTURE0, dispwidth+ff, dispheight+ff );
  glMultiTexCoord2d( GL_TEXTURE1, dispwidth/2 + xoffset + ff, dispheight/2 + ff);
  glMultiTexCoord2d( GL_TEXTURE2, dispwidth/2 + xoffset + ff, dispheight/2 + ff);
  glVertex2s( width, height);

  glMultiTexCoord2d( GL_TEXTURE0, ff, dispheight+ff );
  glMultiTexCoord2d( GL_TEXTURE1, xoffset+ff, dispheight/2 + ff );
  glMultiTexCoord2d( GL_TEXTURE2, xoffset+ff, dispheight/2 + ff );
  glVertex2s( 0, height);

  glEnd();

  glPopMatrix();

  glXSwapBuffers( display, window );

  OpenGLDisplay::GLcheck( "glXSwapBuffers" );

  glFinish();

  /* Check if we stuttered */  

  int64_t ust, mbc, sbc, us;
  struct timeval now;

  gettimeofday( &now, NULL );
  us = 1000000 * now.tv_sec + now.tv_usec;
  long us_diff = us - last_us;

  GetSync( display, window, &ust, &mbc, &sbc );

  bool msg = false;

  if ( (last_mbc != -1) && (mbc != last_mbc + 1) ) {
    long int diff = mbc - last_mbc;
    fprintf( stderr, "[Skipped %ld retraces.]", diff );
    msg = true;
  }

  if ( (last_us != -1) && ( (us_diff < 8000) || (us_diff > 24000) ) ) {
    fprintf( stderr, "%s[Time diff was %ld us.]", msg ? " " : "", (long)us_diff );
    msg = true;
  }

  if ( msg ) {
    fprintf( stderr, "\n" );
  }

  last_mbc = mbc;
  last_us = us;
}
Example #12
0
//--------------------------------------------------------------
void testApp::draw(){
	background.draw(x,y,w,h);
	if (!full) {

	if (drawRef) {
	gui->draw();
	colorImg.draw(320, 500, 320,240);
	recordDepth.draw(640, 0, 320,240);
	CVgrayImage.draw(640, 500, 320,240);
	if (showHandsImage) {
		handsImage.draw(640, 240, 320, 240);
	}

	}
		//recordHandTracker.drawHands();
}
	if (masks) {
		
		
		maskShader.begin();
		
	glActiveTexture(GL_TEXTURE0_ARB);
		colorImg.getTextureReference().bind();
		
		glActiveTexture(GL_TEXTURE1_ARB);
		//allUserMasks.getTextureReference().bind();
		CVgrayImage.getTextureReference().bind();
		glBegin(GL_QUADS);
		
		glMultiTexCoord2d(GL_TEXTURE0_ARB, leftCrop, 0);
		glMultiTexCoord2d(GL_TEXTURE1_ARB, leftCrop, 0);		
		glVertex2f( x, y);
		
		glMultiTexCoord2d(GL_TEXTURE0_ARB, colorImg.getWidth(), 0);
		glMultiTexCoord2d(GL_TEXTURE1_ARB, CVgrayImage.getWidth(), 0);		
		glVertex2f( w, y);
		
		glMultiTexCoord2d(GL_TEXTURE0_ARB, colorImg.getWidth(), colorImg.getHeight()-bottomCrop);
		glMultiTexCoord2d(GL_TEXTURE1_ARB, CVgrayImage.getWidth(), CVgrayImage.getHeight()-bottomCrop);
		glVertex2f(w,h);
		
		glMultiTexCoord2d(GL_TEXTURE0_ARB, leftCrop, colorImg.getHeight()-bottomCrop);
		glMultiTexCoord2d(GL_TEXTURE1_ARB, leftCrop, CVgrayImage.getHeight()-bottomCrop);		
		glVertex2f( x, h);
		
		glEnd();
		
		glActiveTexture(GL_TEXTURE1_ARB);
		CVgrayImage.getTextureReference().unbind();
		
		glActiveTexture(GL_TEXTURE0_ARB);
		colorImg.getTextureReference().unbind();
		
		maskShader.end();
		 
	}
	
	
	//recordHandTracker.drawHands();
	
	
}
Example #13
0
void AlphaMask::maskRect(){
    int srcMargin = 100;
    ofApp *app = ((ofApp*)ofGetAppPtr());
    srcTex = app->blackmagic->colorTexture;
    
    ofFbo srcFbo;
    srcFbo.allocate(1920, 1080 / 2.0);
    srcFbo.begin();
    ofClear(0, 0, 0);
    ofPushMatrix();
    //ofScale(1.0, 0.5);
    srcTex.draw(0, 0, 1920, 1080 / 2.0);
    ofPopMatrix();
    srcFbo.end();
    
    fbo.begin();
    ofClear(0, 0, 0);
    maskShader.begin();
    
    glActiveTexture(GL_TEXTURE0_ARB);
    srcFbo.getTextureReference().bind();
    
    glActiveTexture(GL_TEXTURE1_ARB);
    rectMask[rectMaskNum].getTextureReference().bind();
    
    glBegin(GL_QUADS);
    
    float maskOffsetX =  ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getWidth(), mask.getWidth() / 4.5);
    //float maskOffsetY =  ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getHeight(), mask.getHeight() / 4.5);
    float maskOffsetY =  ofMap(app->oscControl->controlVal[3], 0, 127, -mask.getWidth(), mask.getWidth() / 4.5);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, maskOffsetY);
    glVertex2f(400, 223);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), 0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, maskOffsetY);
    glVertex2f(1520, 223);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, srcTex.getWidth(), srcTex.getHeight() / 2.0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, mask.getWidth() - maskOffsetX, mask.getHeight() - maskOffsetY);
    glVertex2f(1520, 856);
    
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, srcTex.getHeight() / 2.0);
    glMultiTexCoord2d(GL_TEXTURE1_ARB, maskOffsetX, mask.getHeight() - maskOffsetY);
    glVertex2f(400, 856);
    
    glEnd();
    
    glActiveTexture(GL_TEXTURE1_ARB);
    rectMask[rectMaskNum].getTextureReference().unbind();
    
    glActiveTexture(GL_TEXTURE0_ARB);
    srcFbo.getTextureReference().unbind();
    
    maskShader.end();
    fbo.end();
    
    ofSetColor(255, app->oscControl->controlVal[2] * 2);
    fbo.draw(0, 0);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL13_nglMultiTexCoord2d(JNIEnv *__env, jclass clazz, jint texture, jdouble s, jdouble t, jlong __functionAddress) {
	glMultiTexCoord2dPROC glMultiTexCoord2d = (glMultiTexCoord2dPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glMultiTexCoord2d(texture, s, t);
}
Example #15
0
void
TrisetObject::drawTriset(float pnear, float pfar, Vec step)
{
  glEnable(GL_DEPTH_TEST);

  bool black = (m_color.x<0.1 && m_color.y<0.1 && m_color.z<0.1);
  bool has_normals = (m_normals.count() > 0);
  bool per_vertex_color = (m_vcolor.count() > 0 && black);
  if (m_pointMode)
    {
      glEnable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, Global::spriteTexture());
      glTexEnvf( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE );
      glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
      glEnable(GL_POINT_SMOOTH);
      glPointSize(m_pointSize);
      glBegin(GL_POINTS);
      for(int i=0; i<m_triangles.count()/3; i+=m_pointStep)
	{
	  int v0 = m_triangles[3*i];
	  if ( m_texValues[v0].x >= pnear &&
	       m_texValues[v0].x <= pfar )
	    {
	      if (has_normals) glNormal3dv(m_tnormals[v0]);
	      if (per_vertex_color)
		glColor4f(m_drawcolor[v0].x, 
			  m_drawcolor[v0].y, 
			  m_drawcolor[v0].z,
			  m_opacity);

	      glVertex3dv(m_tvertices[v0]);
	    }
	}
      glEnd();
      glPointSize(1);
      glDisable(GL_POINT_SPRITE);
      glActiveTexture(GL_TEXTURE0);
      glDisable(GL_TEXTURE_2D);
    }
  else
    {
      glBegin(GL_TRIANGLES);
      for(int i=0; i<m_triangles.count()/3; i++)
	{
	  int v0 = m_triangles[3*i];
	  int v1 = m_triangles[3*i+1];
	  int v2 = m_triangles[3*i+2];
	  
	  if ( ! ((m_texValues[v0].x < pnear &&
		   m_texValues[v1].x < pnear &&
		   m_texValues[v2].x < pnear) ||
		  (m_texValues[v0].x > pfar  &&
		   m_texValues[v1].x > pfar  &&
		   m_texValues[v2].x > pfar)) )
	    {
	      glMultiTexCoord2d(GL_TEXTURE0,
				m_texValues[v0].y,
				m_texValues[v0].z);
	      if (has_normals) glNormal3dv(m_tnormals[v0]);
	      if (per_vertex_color)
		glColor4f(m_drawcolor[v0].x, 
			  m_drawcolor[v0].y, 
			  m_drawcolor[v0].z,
			  m_opacity);
	      glMultiTexCoord3dv(GL_TEXTURE2, m_tvertices[v0]);
	      glVertex3dv(m_tvertices[v0]+step);
	      
	      glMultiTexCoord2d(GL_TEXTURE0,
				m_texValues[v1].y,
				m_texValues[v1].z);
	      if (has_normals) glNormal3dv(m_tnormals[v1]);
	      if (per_vertex_color)
		glColor4f(m_drawcolor[v1].x, 
			  m_drawcolor[v1].y, 
			  m_drawcolor[v1].z,
			  m_opacity);
	      glMultiTexCoord3dv(GL_TEXTURE2, m_tvertices[v1]);
	      glVertex3dv(m_tvertices[v1]+step);
	      
	      glMultiTexCoord2d(GL_TEXTURE0,
				m_texValues[v2].y,
				m_texValues[v2].z);
	      if (has_normals) glNormal3dv(m_tnormals[v2]);
	      if (per_vertex_color)
		glColor4f(m_drawcolor[v2].x, 
			  m_drawcolor[v2].y, 
			  m_drawcolor[v2].z,
			  m_opacity);
	      glMultiTexCoord3dv(GL_TEXTURE2, m_tvertices[v2]);
	      glVertex3dv(m_tvertices[v2]+step);
	    }
	  
	}
      glEnd();
    }

  glDisable(GL_DEPTH_TEST);
}
Example #16
0
//--------------------------------------------------------------
void testApp::draw(){
    ofBackground(100, 100, 100);
    
    cam.begin();
    
    ofTranslate(position);
    ofSetColor(250, 250, 250);
    model.draw();
    ofSetColor(50, 50, 50);
    light.customDraw();
    
    // left columnn 1 videoplane
    glPushMatrix();
        glTranslatef(-85, 90, -150);
        ofDisableLighting();
    
        if(curMov) {
            ofSetColor(255, 255, 255);
            glActiveTexture(GL_TEXTURE0_ARB);
            curMov->getTextureReference().bind();
        }
    
        glBegin(GL_QUADS);
        if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0,  0);}
        glVertex3f( 0,  0,  0);
        if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, curMov->getWidth(), 0);}
        glVertex3f( 16,  0,  0);
        if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, curMov->getWidth(), curMov->getHeight());}
        glVertex3f( 16, -64,  0);
        if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, curMov->getHeight());}
        glVertex3f( 0, -64,  0);
        if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);}
        glVertex3f( 0,  0,  0);
        glEnd();
    
        if(curMov){
            //deactive and clean up
            glActiveTexture(GL_TEXTURE0_ARB);
            curMov->getTextureReference().unbind();
        }

    glPopMatrix();
    
    // main videoplane
    glPushMatrix();
    glTranslatef(-64, 110, -180);
    ofDisableLighting();
    
    if(curMov) {
        ofSetColor(255, 255, 255);
        glActiveTexture(GL_TEXTURE0_ARB);
        curMov->getTextureReference().bind();
    }
    
    glBegin(GL_QUADS);
    if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0,  0);}
    glVertex3f( 0,  0,  0);
    if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, curMov->getWidth(), 0);}
    glVertex3f( 128,  0,  0);
    if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, curMov->getWidth(), curMov->getHeight());}
    glVertex3f( 128, -64,  0);
    if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, curMov->getHeight());}
    glVertex3f( 0, -64,  0);
    if(curMov){glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);}
    glVertex3f( 0,  0,  0);
    glEnd();
    
    if(curMov){
        //deactive and clean up
        glActiveTexture(GL_TEXTURE0_ARB);
        curMov->getTextureReference().unbind();
    }
    
    glPopMatrix();
    
    ofEnableLighting();
    
    cam.end();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL13_nglMultiTexCoord2d(JNIEnv *env, jclass clazz, jint target, jdouble s, jdouble t, jlong function_pointer) {
	glMultiTexCoord2dPROC glMultiTexCoord2d = (glMultiTexCoord2dPROC)((intptr_t)function_pointer);
	glMultiTexCoord2d(target, s, t);
}
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 ;
}