void NormalGetterApp::normalize(gl::TextureRef _tex){
    {
        gl::ScopedMatrices push;
        gl::ScopedFramebuffer fbo(mOutputFbo);
        gl::clear();
        ci::gl::setMatricesWindow( mOutputFbo->getSize() );
        ci::gl::ScopedViewport view( ci::vec2(0), mOutputFbo->getSize() );
        gl::ScopedGlslProg mGlsl(mNormalGlsl);
        gl::ScopedTextureBind tex0(_tex);
        mNormalGlsl->uniform("uSampler", 0);
        mNormalGlsl->uniform("u_textureSize", vec2(_tex->getWidth(), _tex->getHeight()));
        mNormalGlsl->uniform("bias", bias);
        mNormalGlsl->uniform("invertR", float(invertR ? -1.0 : 1.0) );
        mNormalGlsl->uniform("invertG", float(invertG ? -1.0 : 1.0));
        gl::drawSolidRect(Rectf(vec2(0), _tex->getSize()));
    }
    if( pushFramesToBuffer){
        mPreprocessedImages->pushFront(std::make_pair(mOutputFbo->getColorTexture()->createSource(), currentFrame));
        if(currentFrame == mMovie->getNumFrames()){
            pushFramesToBuffer = false;
            mMovie->setLoop(true);
            mMovie->seekToStart();
        }
        currentFrame++;
    }
}
示例#2
0
void ciApp::setup()
{
	setWindowSize(1280, 720);
	setFrameRate(60.f);
	
	int maxVertUniformsVect;
	glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertUniformsVect);

	mSize = 0;
	mSizePrev = -1;
	mSizeMax = 17;
	mAmplifier = 1.f;

	mExposure = 1.f;
	mGamma = 2.2f;

	printf("max uniform: %i, %i\n", maxVertUniformsVect, mSizeMax);

	mParams = params::InterfaceGl::create(getWindow(), "App parameters", ivec2(250, 300));
	mParams->setPosition(ivec2(20, 250));

	mTexture = gl::Texture::create(loadImage(loadFile(data_path + "demo.png")));
	mFbo = gl::Fbo::create(mTexture->getWidth(), mTexture->getHeight(), gl::Fbo::Format().colorTexture());
	//mShader.setup("filterGaussianBlur");

	filter = hb::GlslFilter::create(mTexture->getSize());
	filter->setParams(mParams);

	vector_blur.setup(getWindowSize());
	vector_blur.setParams(mParams);

	spout_receiver = hb::Receiver::create("Spout DX11 Sender");
	//spout_receiver = hbSpoutReceiver::create("KidsLandSea");
	spout_sender = hb::Sender::create("cinder_spout", mFbo->getWidth(), mFbo->getHeight());

#if 0
	auto ctx = audio::Context::master();

	// The InputDeviceNode is platform-specific, so you create it using a special method on the Context:
	mInputDeviceNode = ctx->createInputDeviceNode();

	// By providing an FFT size double that of the window size, we 'zero-pad' the analysis data, which gives
	// an increase in resolution of the resulting spectrum data.
	auto monitorFormat = audio::MonitorSpectralNode::Format().fftSize(2048).windowSize(1024);
	mMonitorSpectralNode = ctx->makeNode(new audio::MonitorSpectralNode(monitorFormat));

	mInputDeviceNode >> mMonitorSpectralNode;

	// InputDeviceNode (and all InputNode subclasses) need to be enabled()'s to process audio. So does the Context:
	mInputDeviceNode->enable();
	ctx->enable();
#endif
}
void AsyncTextureLoadingApp::setup()
{
    // Enable alpha blending in case our image supports it.
    gl::enableAlphaBlending();
    
    
    // Load the image in a separated thread and returns the ImageSourceRef
    auto asyncLoad = [](DataSourceRef dataSource){
        ImageSourceRef imageSource = loadImage( dataSource );
        return imageSource;
    };
    
    // The second callback is executed in the main thread so any OpenGL resources can be created here.
    auto textureCreation = [this](ImageSourceRef imageSource){
        mTexture = gl::Texture::create( imageSource );
        
        // It's ok to do that in the main thread:
        setWindowSize( mTexture->getWidth(), mTexture->getHeight() );
    };

    // Use the templated version if you want to pass an object from the loading thread to the main thread. Because we are providing the load function with two callbacks there's no need to specify Options().asynchronous() like we would do with only one callback.
    AssetManager::load<ImageSourceRef>( "cinder_logo_alpha.png", asyncLoad, textureCreation );
    
        
    // The following does exactly the same but is shorter.
    /*
     
    AssetManager::load<ImageSourceRef>( "cinder_logo_alpha.png",
     
     // Load the image in a separated thread and returns the ImageSourceRef
    [this](DataSourceRef dataSource){
        ImageSourceRef imageSource = loadImage( dataSource );
        return imageSource;
    },
     
     // The second callback is executed in the main thread so any OpenGL resources can be created here.
    [this](ImageSourceRef imageSource){
        mTexture = gl::Texture::create( imageSource );
    } );
     
    */
}
void PointCloudApp::draw()
{
	gl::viewport( getWindowSize() );
	gl::clear();
	gl::setMatrices( mCamUi.getCamera() );
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	if ( mSurfaceColor ) {
		if ( mTextureColor ) {
			mTextureColor->update( *mSurfaceColor );
		} else {
			mTextureColor = gl::Texture::create( *mSurfaceColor );
		}
		mTextureColor->bind( 0 );
	}
	if ( mChannelDepth ) {
		if ( mTextureDepth ) {
			gl::ScopedTextureBind scopeTextureBind( mTextureDepth->getTarget(), mTextureDepth->getId() );
			glTexSubImage2D( mTextureDepth->getTarget(), 0, 0, 0,
				mTextureDepth->getWidth(), mTextureDepth->getHeight(),
				GL_RED_INTEGER,	GL_UNSIGNED_SHORT, mChannelDepth->getData() );
		} else {
			mTextureDepth = gl::Texture::create( 
				mChannelDepth->getWidth(), mChannelDepth->getHeight(), 
				gl::Texture::Format().dataType( GL_UNSIGNED_SHORT ).internalFormat( GL_R16UI ) );
		}
		mTextureDepth->bind( 1 );
	}
	if ( mSurfaceDepthToCameraTable && !mTextureDepthToCameraTable ) {
		mTextureDepthToCameraTable = gl::Texture::create( *mSurfaceDepthToCameraTable );
		mTextureDepthToCameraTable->bind( 2 );
	}
	if ( mSurfaceDepthToColorTable ) {
		if ( mTextureDepthToColorTable ) {
			mTextureDepthToColorTable->update( *mSurfaceDepthToColorTable );
		} else {
			mTextureDepthToColorTable = gl::Texture::create( 
				*mSurfaceDepthToColorTable,
				gl::Texture::Format().dataType( GL_FLOAT ) );
		}
		mTextureDepthToColorTable->bind( 3 );
	}

	gl::ScopedGlslProg scopeGlsl( mGlslProg );
	gl::setDefaultShaderVars();
	mGlslProg->uniform( "uTextureColor",				0 );
	mGlslProg->uniform( "uTextureDepth",				1 );
	mGlslProg->uniform( "uTextureDepthToCameraTable",	2 );
	mGlslProg->uniform( "uTextureDepthToColorTable",	3 );

	gl::draw( mVboMesh );
	
	if ( mTextureColor ) {
		mTextureColor->unbind();
	}
	if ( mTextureDepth ) {
		mTextureDepth->unbind();
	}
	if ( mTextureDepthToCameraTable ) {
		mTextureDepthToCameraTable->unbind();
	}
	if ( mTextureDepthToColorTable ) {
		mTextureDepthToColorTable->unbind();
	}

	mParams->draw();
}