コード例 #1
0
ファイル: main.cpp プロジェクト: CurtisMcKinney/Simulacra
void Simulacra::helix()
{
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);

    // render a simple scene into mFboScene
    helixShader.bind();
    gl::translate(0,0,0);
    helixFBO.bindFramebuffer();

    helixShader.uniform("time",Vec2f(sin(rotation),1-sin(rotation*0.71)));
    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    gl::drawSolidRect(cinder::Rectf(0,0,getWindowWidth(),getWindowHeight()));
    helixFBO.unbindFramebuffer();
    helixShader.unbind();

    //Revert back to screen
    gl::color(cinder::ColorA(1,1,1,1));
    applyHelixShader.bind();
    finalFBO.bindTexture(0);
    applyHelixShader.uniform("qt_Texture0",0);
    helixFBO.bindTexture(1);
    applyHelixShader.uniform("qt_Texture1",1);

    gl::drawSolidRect(cinder::Rectf(0,getWindowHeight(),getWindowWidth(),0));
    applyHelixShader.unbind();
    helixFBO.unbindTexture();
    finalFBO.unbindTexture();

    gl::color(ColorA(1,1,1,1));
}
コード例 #2
0
void KinectEcard::renderSubstractedVideo(){
	mSubstractedVideoFbo.bindFramebuffer();

	gl::pushMatrices();
	{
		// clear FBO
		gl::clear( Color::black() );
		gl::color( Color::white() );

		//
		gl::setMatricesWindowPersp( mSubstractedVideoFbo.getSize() );

		mSubstractShader.bind();
		mSubstractShader.uniform( "tex0", 0 );
		mSubstractShader.uniform( "tex1", 1 );
		mSubstractShader.uniform( "tex2", 2 );
		mSubstractShader.uniform( "tex3", 3 );

		mVideoFbo.bindTexture(0);
		mDepthFbo.bindTexture(1);
		mStoredVideoFbo.bindTexture(2);
		mStoredDepthFbo.bindTexture(3);
		
		gl::drawSolidRect( mSubstractedVideoFbo.getBounds() );

		mVideoFbo.unbindTexture();
		mDepthFbo.unbindTexture();
		mStoredVideoFbo.unbindTexture();
		mStoredDepthFbo.unbindTexture();

		mSubstractShader.unbind();
	}
	gl::popMatrices();

	mSubstractedVideoFbo.unbindFramebuffer();
}
コード例 #3
0
ファイル: main.cpp プロジェクト: ChristophPacher/Cinder
void ShadowMapSample::draw()
{
	gl::clear();
	gl::enableDepthWrite();
	glEnable( GL_LIGHTING );
	updateShadowMap();

	gl::enableDepthRead();

	glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
	mShader.bind();
	mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) );
	
	if( mLookThroughCamera )
		gl::setMatrices( *mCamera );
	else
		gl::setMatrices( mLight->getShadowCamera() );
	mLight->update( *mCamera );

	glPushMatrix();
		mBackboard.draw();
		mTorus.draw();
		gl::drawCube( vec3::zero(), vec3( 1, 1, 1 ) );
	glPopMatrix();
	
	mShader.unbind();
	mDepthFbo.unbindTexture();
	
	// Draw the lighting frustum unless we're looking through it
	if( mLookThroughCamera ) {
		glDisable( GL_LIGHTING );
		glColor3f( 1.0f, 1.0f, 0.1f );
		gl::drawFrustum( mLight->getShadowCamera() );
	}
	
	if( mDrawDepthMap ) { // there are faster ways to achieve this, but this is a handy way to see the depth map
		gl::setMatricesWindow( getWindowSize() );
		Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() );
		ip::hdrNormalize( &shadowMapSurface );
		gl::color( Color::white() );
		gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128, 128 ) );
	}
}
コード例 #4
0
ファイル: GroveApp.cpp プロジェクト: r-a-v-a-s/GroveScript
void Grove::copyBlur(gl::Fbo& source, gl::Fbo& target, Vec2f sampleOffset)
{
	// bind the blur shader
	mBlurShader.bind();
	mBlurShader.uniform("tex0", 0); // use texture unit 0
	mBlurShader.uniform("sampleOffset", sampleOffset);

	// copy a horizontally blurred version of our scene into the first blur Fbo
	gl::setViewport( target.getBounds() );
	target.bindFramebuffer();
		source.bindTexture(0);
		gl::pushMatrices();
		gl::setMatricesWindow(target.getSize(), false);
			gl::clear( Color::black() );
			gl::drawSolidRect( target.getBounds() );
		gl::popMatrices();
		source.unbindTexture();
	target.unbindFramebuffer();	

	// unbind the shader
	mBlurShader.unbind();
}
コード例 #5
0
void BloomingNeonApp::draw()
{
	// clear our window
	gl::clear( Color::black() );

	// store our viewport, so we can restore it later
	Area viewport = gl::getViewport();

	// render scene into mFboScene using illumination texture
	mTextureIllumination.enableAndBind();
	mTextureSpecular.bind(1);
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
			gl::setMatricesWindow(SCENE_SIZE, SCENE_SIZE, false);
			gl::clear( Color::black() );
			render();
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// bind the blur shader
	mShaderBlur.bind();
	mShaderBlur.uniform("tex0", 0); // use texture unit 0
 
	// tell the shader to blur horizontally and the size of 1 pixel
	mShaderBlur.uniform("sample_offset", Vec2f(1.0f/mFboBlur1.getWidth(), 0.0f));
	mShaderBlur.uniform("attenuation", 2.5f);

	// copy a horizontally blurred version of our scene into the first blur Fbo
	gl::setViewport( mFboBlur1.getBounds() );
	mFboBlur1.bindFramebuffer();
		mFboScene.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow(BLUR_SIZE, BLUR_SIZE, false);
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur1.getBounds() );
		gl::popMatrices();
		mFboScene.unbindTexture();
	mFboBlur1.unbindFramebuffer();	
 
	// tell the shader to blur vertically and the size of 1 pixel
	mShaderBlur.uniform("sample_offset", Vec2f(0.0f, 1.0f/mFboBlur2.getHeight()));
	mShaderBlur.uniform("attenuation", 2.5f);

	// copy a vertically blurred version of our blurred scene into the second blur Fbo
	gl::setViewport( mFboBlur2.getBounds() );
	mFboBlur2.bindFramebuffer();
		mFboBlur1.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow(BLUR_SIZE, BLUR_SIZE, false);
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur2.getBounds() );
		gl::popMatrices();
		mFboBlur1.unbindTexture();
	mFboBlur2.unbindFramebuffer();

	// unbind the shader
	mShaderBlur.unbind();

	// render scene into mFboScene using color texture
	mTextureColor.enableAndBind();
	mTextureSpecular.bind(1);
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
			gl::setMatricesWindow(SCENE_SIZE, SCENE_SIZE, false);
			gl::clear( Color::black() );
			render();
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// restore the viewport
	gl::setViewport( viewport );

	// because the Fbo's have their origin in the LOWER-left corner,
	// flip the Y-axis before drawing
	gl::pushModelView();
	gl::translate( Vec2f(0, 256) );
	gl::scale( Vec3f(1, -1, 1) );

	// draw the 3 Fbo's 
	gl::color( Color::white() );
	gl::draw( mFboScene.getTexture(), Rectf(0, 0, 256, 256) );
	drawStrokedRect( Rectf(0, 0, 256, 256) );

	gl::draw( mFboBlur1.getTexture(), Rectf(260, 0, 260 + 256, 256) );
	drawStrokedRect( Rectf(260, 0, 260 + 256, 256) );

	gl::draw( mFboBlur2.getTexture(), Rectf(520, 0, 520 + 256, 256) );
	drawStrokedRect( Rectf(520, 0, 520 + 256, 256) );

	// draw our scene with the blurred version added as a blend
	gl::color( Color::white() );
	gl::draw( mFboScene.getTexture(), Rectf(780, 0, 780 + 256, 256) );

	gl::enableAdditiveBlending();
	gl::draw( mFboBlur2.getTexture(), Rectf(780, 0, 780 + 256, 256) );
	gl::disableAlphaBlending();
	drawStrokedRect( Rectf(780, 0, 780 + 256, 256) );
	
	// restore the modelview matrix
	gl::popModelView();

	// draw info
	gl::enableAlphaBlending();
	gl::drawStringCentered("Basic Scene", Vec2f(128, 236));
	gl::drawStringCentered("First Blur Pass (Horizontal)", Vec2f(260 + 128, 236));
	gl::drawStringCentered("Second Blur Pass (Vertical)", Vec2f(520 + 128, 236));
	gl::drawStringCentered("Final Scene", Vec2f(780 + 128, 236));
	gl::disableAlphaBlending();
}
コード例 #6
0
ファイル: TextTestApp.cpp プロジェクト: proalias/ee_app
void TextTestApp::draw()
{
	// this pair of lines is the standard way to clear the screen in OpenGL
	glClearColor( 0,0,0,1 );
	glClear( GL_COLOR_BUFFER_BIT );
	
	if (flipScreen==true){
		gl::pushMatrices();
		
		gl::scale( Vec3f(-1, 1, 1) );
		gl::translate( Vec2f(-ci::app::getWindowWidth(), 0 ) );
		gl::translate( Vec3f(-1, 1, 1) );
	}

	gl::enableAlphaBlending();
	gl::enableAdditiveBlending();

	mbackground.draw();

	drawSkeleton();

	// FONT NOW GETS RENDERED AFTER SCENE SO WE CAN OVERRIDE DRAW OPERATION IF REQUIRED
	currentScene->draw();

	myFont.draw();	
	
	// kill this all and refresh
	gl::disableAlphaBlending();
	gl::enableAdditiveBlending();

	// store our viewport, so we can restore it later
	Area viewport = gl::getViewport();

	// render a simple scene into mFboScene
	gl::setViewport( mFboScene.getBounds() );
	mFboScene.bindFramebuffer();
		gl::pushMatrices();
		gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( ColorA( 0,0,0,1 ));
			fgParticles.draw();
			//gl::drawSolidCircle( Vec2f(50,50), 20 );
			//gl::draw( mFboScene.getTexture() );//TODO - screenshot?
		gl::popMatrices();
	mFboScene.unbindFramebuffer();

	// bind the blur shader
	mShaderBlur.bind();
	mShaderBlur.uniform("tex0", 0); // use texture unit 0
 
	// tell the shader to blur horizontally and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(1.0f/mFboBlur1.getWidth(), 0.0f));

	// copy a horizontally blurred version of our scene into the first blur Fbo
	
	gl::setViewport( mFboBlur1.getBounds() );
	mFboBlur1.bindFramebuffer();
		mFboScene.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur1.getBounds() );
		gl::popMatrices();
		mFboScene.unbindTexture();
	mFboBlur1.unbindFramebuffer();

 
	// tell the shader to blur vertically and the size of 1 pixel
	mShaderBlur.uniform("sampleOffset", Vec2f(0.0f, 1.0f/mFboBlur2.getHeight()));

	// copy a vertically blurred version of our blurred scene into the second blur Fbo
	gl::setViewport( mFboBlur2.getBounds() );
	mFboBlur2.bindFramebuffer();
		mFboBlur1.bindTexture(0);
		gl::pushMatrices();
			gl::setMatricesWindow( viewport.getWidth(), viewport.getHeight(), false );
			gl::clear( Color::black() );
			gl::drawSolidRect( mFboBlur2.getBounds() );
		gl::popMatrices();
		mFboBlur1.unbindTexture();
	mFboBlur2.unbindFramebuffer();

	// unbind the shader
	mShaderBlur.unbind();

	// restore the viewport
	gl::setViewport( viewport );
	// because the Fbo's have their origin in the LOWER-left corner,
	// flip the Y-axis before drawing
	gl::pushModelView();
	gl::translate( Vec2f(0, 0 ) );// viewport.getHeight() ) );
	gl::scale( Vec3f(1, 1, 1) );

	// draw the 3 Fbo's 
	//gl::color( Color::white() );
	//gl::draw( mFboScene.getTexture(), Rectf(0, 0, 256, 256) );
	//gl::draw( mFboBlur1.getTexture(), Rectf(260, 0, 260 + 256, 256) );
	//gl::draw( mFboBlur2.getTexture(), Rectf(520, 0, 520 + 256, 256) );

	// draw our scene with the blurred version added as a blend
	gl::color( Color::white() );
	
	gl::enableAdditiveBlending();
	gl::draw( mFboScene.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));

	gl::draw( mFboBlur2.getTexture(), Rectf(0, 0, viewport.getWidth(), viewport.getHeight() ));
	gl::disableAlphaBlending();

	// restore the modelview matrix
	gl::popModelView();

	if (flipScreen == true){
		gl::popMatrices();
	}
	
	gl::color( Color(1.0,1.0,1.0) );
	
	
	//These are for debug only
	//drawTitleSafeArea();
	//OutlineParams::getInstance()->draw();
}
コード例 #7
0
ファイル: BrainbowApp.cpp プロジェクト: JAGormley/Brainbow
void BrainbowApp::draw()
{
	gl::setViewport( getWindowBounds() );
    
    // SCREENPULSE
    // changes every 12.5 seconds
    float gray = (cos(getElapsedSeconds()/4)*.3)/2 ;
    float otherCol = (sin(getElapsedSeconds()/4)*.2)/2;
    
    screenCol = Vec3f (lightFade+gray, lightFade, (lightFade*2)-otherCol);
    
    if (sceneOne)
        gl::clear( Color(lightFade+gray, lightFade, (lightFade*2)-otherCol) );
    if (sceneTwo)
        gl::clear( Color(1, 1, 1) );
    
    
    // FADE IN INTRO
    if (lightFade < .5){
        lightFade += .0005;
    }
    
    if (mHands.empty())
        mLight->disable();
    
    updateShadowMap();
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    mShader.bind();
    glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
    mShader.bind();
    
    
    // FIRST SCENE
    if (sceneOne){
        
        // disc
        if (zshift > 0){
            glPushMatrix();
            glTranslated( 640, 400, zshift - 200);
            if (shift2 && discOp > 1)
                glScalef(discOp, discOp, 0);
            //    cout << discOp << endl;
            mDisc.draw();
            glPopMatrix();
        }
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        //    if (lightFade > .45f)
        mCloud.update(scaledX, scaledY, scaledZ, diamondFade, 1);
        glPopMatrix();
        
        if (drawDiamond){
            glPushMatrix();
            glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift);
            mDiamond.draw();
            glPopMatrix();
        }
    }
    
    // SECOND SCENE
    if (sceneTwo){
        
        mLight->lookAt( Vec3f(scaledX, scaledY, scaledZ +200), Vec3f (getWindowWidth()*.05, getWindowHeight() * 0.5f, 0.0f ));
        
        // cursor
        glPushMatrix();
        glTranslated( scaledX, scaledY, scaledZ );
        mCur.draw();
        
        if (scaledZ < 375 && scaledZ > 350)
            gl::drawSphere(Vec3f(0,0,0), (scaledZ-350)*.4);
        if (scaledZ >= 375)
            gl::drawSphere(Vec3f(0,0,0), 25*.4);
        glPopMatrix();
        
        
        // rotate whole scene; implement this later:
        
        //        if (targetFilled){
        //            glPushMatrix();
        //            glRotatef(getElapsedSeconds()*10, Vec3f (640, 400, 350) );
        //        }
        for (int i = 0; i < cubes.size() ; i++){
            glPushMatrix();
            glTranslatef(cubes[i].getLocation());
            cubes[i].update(.01f, screenCol);
            glPopMatrix();
        }
        offCounter = 0;        
        for (int i = 0; i < targets.size() ; i++){
            glPushMatrix();
            glTranslatef(targets[i].getLocation());
            targets[i].update(.01f, handPos, screenCol);
            if (targets[i].getBoxed() && targets[i].getBoxNumber() < 15 ){
                addCube(targets[i].getLocation().x, targets[i].getLocation().y, targets[i].getLocation().z);
                targets[i].addBox();
                if (targets[i].getBoxNumber() == 15)
                mAudio.playTraz("box");   
            }
            
            glPopMatrix();
            if (targets[i].getChargeSound()){
                if (!mAudio.isPlaying("charge")){
                    offCounter = 0;
                    mAudio.playTraz("charge");
                }
            }
            //stop charge if deactivated
            if (!targets[i].getChargeSound()){
                offCounter++;
            }
            if (offCounter == targets.size()){
                mAudio.stopTraz("charge");
            }
        }
        //  (from above)
        //   if (targetFilled)
        //   glPopMatrix();
        //
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        mCloud.update(0, 0, 0, 0, 2);
        glPopMatrix();
    }
    
    mShader.unbind();
    mDepthFbo.unbindTexture();
    
    //    writeImage( getHomeDirectory() / ("image_" + toString( getElapsedFrames() ) + ".png"), copyWindowSurface() );
	
}
コード例 #8
0
void SmoothDisplacementMappingApp::draw()
{
	gl::clear();

	// render background
	if( mBackgroundTexture && mBackgroundShader )
	{
		mBackgroundShader.bind();
		mBackgroundShader.uniform( "texture", 0 );
		mBackgroundShader.uniform( "hue", float( 0.025 * getElapsedSeconds() ) );
		gl::draw( mBackgroundTexture, getWindowBounds() );
		mBackgroundShader.unbind();
	}//*/

	// if enabled, show the displacement and normal maps 
	if(mDrawTextures) 
	{	
		gl::color( Color(0.05f, 0.05f, 0.05f) );
		gl::draw( mDispMapFbo.getTexture(), Vec2f(0,0) );
		gl::color( Color(1, 1, 1) );
		gl::draw( mNormalMapFbo.getTexture(), Vec2f(256,0) );
	}

	// setup the 3D camera
	gl::pushMatrices();
	gl::setMatrices( mCamera );

	// setup render states
	gl::enableAdditiveBlending();
	if(mDrawWireframe) 
		gl::enableWireframe();

	// draw undisplaced mesh if enabled
	if(mDrawOriginalMesh)
	{
		gl::color( ColorA(1, 1, 1, 0.2f) );
		gl::draw( mVboMesh );
	}

	if( mDispMapFbo && mNormalMapFbo && mMeshShader )
	{
		// bind the displacement and normal maps, each to their own texture unit
		mDispMapFbo.getTexture().bind(0);
		mNormalMapFbo.getTexture().bind(1);

		// render our mesh using vertex displacement
		mMeshShader.bind();
		mMeshShader.uniform( "displacement_map", 0 );
		mMeshShader.uniform( "normal_map", 1 );
		mMeshShader.uniform( "falloff_enabled", mEnableShader );

		gl::color( Color::white() );
		gl::draw( mVboMesh );

		mMeshShader.unbind();

		// unbind texture maps
		mNormalMapFbo.unbindTexture();
		mDispMapFbo.unbindTexture();
	}
	
	// clean up after ourselves
	gl::disableWireframe();
	gl::disableAlphaBlending();
	
	gl::popMatrices();//*/
}
コード例 #9
0
ファイル: main.cpp プロジェクト: CurtisMcKinney/Simulacra
void Simulacra::blur()
{
    //    glEnable( GL_TEXTURE_2D );
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    Area viewport = gl::getViewport();

    // render a simple scene into mFboScene
    gl::setViewport( sceneFBO.getBounds() );
    sceneFBO.bindFramebuffer();
    //        gl::pushMatrices();
    //            gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    gl::pushMatrices();
    gl::setMatrices(camera);
    try{
        //Draw points
        synthMenu->drawTerrain();
        synthMenu->drawSynths();
    } catch(...) {
        std::cout << "drawing error!" << std::endl;
    }
    gl::popMatrices();
    sceneFBO.unbindFramebuffer();


    // bind the blur shader
    blurShader.bind();
    blurShader.uniform("tex0", 0); // use texture unit 0

    // tell the shader to blur horizontally and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(1.0f/blurFBO1.getWidth(), 0.0f));

    //FIRST PASS
    // copy a horizontally blurred version of our scene into the first blur Fbo
    gl::setViewport( blurFBO1.getBounds() );
    blurFBO1.bindFramebuffer();
    sceneFBO.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO1.getBounds() );
    gl::popMatrices();
    sceneFBO.unbindTexture();
    blurFBO1.unbindFramebuffer();

    // tell the shader to blur vertically and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(0.0f, 1.0f/blurFBO2.getHeight()));

    // copy a vertically blurred version of our blurred scene into the second blur Fbo
    gl::setViewport( blurFBO2.getBounds() );
    blurFBO2.bindFramebuffer();
    blurFBO1.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO2.getBounds() );
    gl::popMatrices();
    blurFBO1.unbindTexture();
    blurFBO2.unbindFramebuffer();

    //SECOND PASS
    // copy a horizontally blurred version of our scene into the first blur Fbo
    blurShader.uniform("sampleOffset", Vec2f(1.0f/blurFBO1.getWidth(), 0.0f));
    gl::setViewport( blurFBO1.getBounds() );
    blurFBO1.bindFramebuffer();
    blurFBO2.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO1.getBounds() );
    gl::popMatrices();
    blurFBO2.unbindTexture();
    blurFBO1.unbindFramebuffer();

    // tell the shader to blur vertically and the size of 1 pixel
    blurShader.uniform("sampleOffset", Vec2f(0.0f, 1.0f/blurFBO2.getHeight()));

    // copy a vertically blurred version of our blurred scene into the second blur Fbo
    gl::setViewport( blurFBO2.getBounds() );
    blurFBO2.bindFramebuffer();
    blurFBO1.bindTexture(0);
    gl::pushMatrices();
    gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
    gl::clear( ColorA(0,0,0,0) );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor4f(1,1,1,1);
    gl::drawSolidRect( blurFBO2.getBounds() );
    gl::popMatrices();
    blurFBO1.unbindTexture();
    blurFBO2.unbindFramebuffer();

    if(section == 1)
    {
        //SECOND PASS
        // copy a horizontally blurred version of our scene into the first blur Fbo
        blurShader.uniform("sampleOffset", Vec2f(3.0f/blurFBO1.getWidth(), 0.0f));
        gl::setViewport( blurFBO1.getBounds() );
        blurFBO1.bindFramebuffer();
        blurFBO2.bindTexture(0);
        gl::pushMatrices();
        gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
        gl::clear( ColorA(0,0,0,0) );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glColor4f(1,1,1,1);
        gl::drawSolidRect( blurFBO1.getBounds() );
        gl::popMatrices();
        blurFBO2.unbindTexture();
        blurFBO1.unbindFramebuffer();

        // tell the shader to blur vertically and the size of 1 pixel
        blurShader.uniform("sampleOffset", Vec2f(0.0f, 3.0f/blurFBO2.getHeight()));

        // copy a vertically blurred version of our blurred scene into the second blur Fbo
        gl::setViewport( blurFBO2.getBounds() );
        blurFBO2.bindFramebuffer();
        blurFBO1.bindTexture(0);
        gl::pushMatrices();
        gl::setMatricesWindow(FBO_WIDTH, FBO_HEIGHT, false);
        gl::clear( ColorA(0,0,0,0) );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glColor4f(1,1,1,1);
        gl::drawSolidRect( blurFBO2.getBounds() );
        gl::popMatrices();
        blurFBO1.unbindTexture();
        blurFBO2.unbindFramebuffer();
    }

    // unbind the shader
    blurShader.unbind();

    //gl::translate(0,0,250);

    gl::setViewport( viewport );
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA,GL_ONE);
    // draw our scene with the blurred version added as a blend
    glColor4f(1,1,1,1);
    //

    gl::enableAlphaBlending(true);

    if(section==1)
    {
        finalFBO.bindFramebuffer();
    }
    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    if(section!=1)
    {
        gl::pushMatrices();
        gl::setMatrices(camera);
        synthMenu->drawTerrain();
        synthMenu->drawSynths();
        gl::popMatrices();

    }
    gl::enableAdditiveBlending();

    if(section == 1 || section == 2 || section == 3)
    {
        //        gl::enableAlphaBlending(true);
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
        gl::draw( blurFBO2.getTexture(), getWindowBounds() );
    }
    gl::draw( blurFBO2.getTexture(), getWindowBounds() );

    gl::disableAlphaBlending();
    if(section==1)
    {
        finalFBO.unbindFramebuffer();
    }
}
コード例 #10
0
ファイル: main.cpp プロジェクト: CurtisMcKinney/Simulacra
void Simulacra::drawSection2()
{
    section3FBO.bindFramebuffer();
    Area area = getWindowBounds();
    area.expand(0.9,0.9);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_INTERPOLATE);
    gl::draw(section3FBO.getTexture(),area);
    //    gl::pushMatrices();
    //    gl::setMatrices(camera);
    //    gl::pushMatrices();
    gl::disableDepthWrite();
    gl::disableDepthRead();
    gl::enableAlphaBlending();
    //    gl::clear(ColorA(0,0,0,0.01),true);
    //    if(bClear) {
    //    if(rand()%100>90) {
    //        bClear = false;
    //    }
    //    gl::clear(ColorA(0,0,0,0.0011));
    //    gl::translate(getWindowWidth()*0.4,0,0);
    //    gl::rotate(Vec3f(0,0,rotAmt*0.00004));
    //    gl::translate(getWindowWidth()*-0.4,0,0);
    //    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    /*
    } else {

        if(rand()%100>90) {
            gl::translate(getWindowWidth()*0.4,0,0);
//            gl::rotate(Vec3f(rotAmt*-0.15,0,rotAmt*-0.15));
            gl::rotate(Vec3f(0,0,rotAmt*0.00002));
            gl::translate(getWindowWidth()*-0.4,0,0);
            int z = (rand()%200)-100;

            glClear( GL_DEPTH_BUFFER_BIT );
            if(rand()%100>90) {
                bClear = true;
            }
        }
    }
    */
    //    gl::enableDepthWrite();
    //    gl::enableDepthRead();


    //Rotating Camera view
    //    gl::pushMatrices();
    //    gl::translate(0,0,-100);
    //    gl::translate(0,0,-getWindowHeight()*0.5);
    //    gl::rotate(Vec3f(0,rotAmt,0));
    //    gl::translate(0,0,getWindowHeight()*0.5);

    //Lighting
    gl::pushMatrices();
    gl::setMatrices(camera);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);

    //Light 1
    //    GLfloat light_position[] = {300*cos(rotation*0.05),300*sin(rotAmt*0.075),0,0.0};
    GLfloat light_position[4] = {0, 0, 0, 0};
    light_position[0] = 300*cos(rotation*0.05);
    light_position[1] = 300*sin(rotAmt*0.075);
    glLightfv( GL_LIGHT0, GL_POSITION, light_position );
    glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.000000001f );
    glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.000000000f );
    glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.000000000f );
    //    GLfloat lightColor[] = {0.5f,0.9f,1,1};
    //    glLightfv( GL_LIGHT0,GL_DIFFUSE, lightColor);
    //    oscThread->drawSection2();

    glColor4f(0.7,0.7,0.7,(1.0));
    gl::disableDepthWrite();
    gl::disableDepthRead();
    gl::enableAlphaBlending();
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SUBTRACT);
    spheroid->draw();
    synthMenu->drawTerrain();
    gl::disableDepthWrite();
    gl::disableDepthRead();
    gl::enableAlphaBlending();
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    synthMenu->drawSynths();

    //    gl::popMatrices();
    section3FBO.unbindFramebuffer();
    gl::popMatrices();


    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    gl::enableDepthWrite();
    gl::enableDepthRead();
    gl::disableAlphaBlending();

    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    //    glEnable(GL_TEXTURE_2D);
    //    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    gl::draw(section3FBO.getTexture(),getWindowBounds());
    sceneFBO.unbindTexture();
    synthMenu->drawTerrain();
}
コード例 #11
0
ファイル: main.cpp プロジェクト: CurtisMcKinney/Simulacra
void Simulacra::drawSection4()
{
    section3FBO.bindFramebuffer();
    gl::disableDepthWrite();
    gl::disableDepthRead();
    gl::enableAlphaBlending();
    gl::color(ColorA(0,0,0,0.01));
    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
    gl::drawSolidRect(
                Rectf(
                    cinder::app::getWindowBounds().getX1(),
                    cinder::app::getWindowBounds().getY1(),
                    cinder::app::getWindowBounds().getX2(),
                    cinder::app::getWindowBounds().getY2()
                    )
                );
    gl::enableAdditiveBlending();
    //    Area area = getWindowBounds();
    //    area.expand(1.1,1.1);
    //    gl::draw(section3FBO.getTexture(),area);
    //    gl::clear(ColorA(0,0,0,1));
    //    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );



    //Draw using Camera Perspective
    gl::pushMatrices();
    gl::setMatrices(camera);

    //Lighting
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);
    GLfloat light_position[] = {0,100,-100,0.5};
    glLightfv( GL_LIGHT0, GL_POSITION, light_position );
    glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.00f );
    glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0000f );
    glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.00f );


    synthMenu->drawTerrain();
    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SUBTRACT);
    synthMenu->drawSynths();
    gl::popMatrices();
    //    blur();
    section3FBO.unbindFramebuffer();

    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    gl::enableDepthWrite();
    gl::enableDepthRead();
    gl::disableAlphaBlending();

    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    gl::draw(section3FBO.getTexture(),getWindowBounds());
    sceneFBO.unbindTexture();
}
コード例 #12
0
ファイル: FolApp.cpp プロジェクト: gaborpapp/apps
void FolApp::draw()
{
    gl::clear( Color::black() );

    if ( !mDepthTexture )
        return;

    // blur depth
    mDepthFbo.bindFramebuffer();
    gl::setMatricesWindow( mDepthFbo.getSize(), false );
    gl::setViewport( mDepthFbo.getBounds() );

    mBlurShader.bind();

    mBlurShader.uniform( "kernelSize", (float)mBlurKernelTexture.getWidth() );
    mBlurShader.uniform( "invKernelSize", 1.f / mBlurKernelTexture.getWidth() );
    mBlurShader.uniform( "imageTex", 0 );
    mBlurShader.uniform( "kernelTex", 1 );
    mBlurShader.uniform( "blurAmount", mBlurAmount );

    // pass 1
    glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT );

    //gl::enable( GL_TEXTURE_2D );
    mDepthTexture.bind( 0 );
    mBlurKernelTexture.bind( 1 );
    mBlurShader.uniform( "stepVector", Vec2f( 1. / mDepthTexture.getWidth(), 0. ) );

    gl::drawSolidRect( mDepthFbo.getBounds() );

    mDepthTexture.unbind();

    // pass 2
    glDrawBuffer( GL_COLOR_ATTACHMENT1_EXT );

    mDepthFbo.bindTexture( 0 );
    mBlurShader.uniform( "stepVector", Vec2f( 0., 1. / mDepthFbo.getHeight() ) );
    gl::drawSolidRect( mDepthFbo.getBounds() );

    mDepthFbo.unbindTexture();
    mBlurKernelTexture.unbind();
    mBlurShader.unbind();

    mDepthFbo.unbindFramebuffer();

    // wave output
    mOutputFbo.bindFramebuffer();
    gl::setMatricesWindow( mOutputFbo.getSize(), false );
    gl::setViewport( mOutputFbo.getBounds() );

    gl::clear( Color::black() );
    gl::disableDepthRead();
    gl::disableDepthWrite();

    gl::enableAdditiveBlending();
    gl::color( ColorA( 1, 1, 1, .0195 ) );

    gl::pushMatrices();
    gl::scale( Vec2f( getWindowWidth() / (float)VBO_X_SIZE,
                      getWindowHeight() / (float)VBO_Y_SIZE) );

    mDepthFbo.getTexture( 1 ).bind();
    mWaveShader.bind();
    mWaveShader.uniform( "tex", 0 );
    mWaveShader.uniform( "invSize", Vec2f( mStep / mDepthFbo.getWidth(),
                                           mStep / mDepthFbo.getHeight() ) );
    mWaveShader.uniform( "clip", mClip );
    gl::draw( mVboMesh );
    mWaveShader.unbind();

    gl::popMatrices();

    gl::disableAlphaBlending();
    mOutputFbo.unbindFramebuffer();

    // bloom
    mBloomFbo.bindFramebuffer();

    gl::setMatricesWindow( mBloomFbo.getSize(), false );
    gl::setViewport( mBloomFbo.getBounds() );

    gl::color( Color::white() );
    mOutputFbo.getTexture().bind();

    mBloomShader.bind();
    for (int i = 0; i < 8; i++)
    {
        glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT + i );
        mBloomShader.uniform( "iteration", i );
        gl::drawSolidRect( mBloomFbo.getBounds() );
        mBloomFbo.bindTexture( 0, i );
    }
    mBloomShader.unbind();

    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
    mBloomFbo.unbindFramebuffer();

    // output mixer
    gl::setMatricesWindow( getWindowSize() );
    gl::setViewport( getWindowBounds() );

    mMixerShader.bind();

    gl::enable( GL_TEXTURE_2D );

    mOutputFbo.getTexture().bind( 0 );
    for (int i = 0; i < 8; i++)
    {
        mBloomFbo.getTexture( i ).bind( i + 1 );
    }

    gl::drawSolidRect( mOutputFbo.getBounds() );
    gl::disable( GL_TEXTURE_2D );
    mMixerShader.unbind();

    //gl::draw( mOutputFbo.getTexture(), getWindowBounds() );
    //gl::draw( mDepthFbo.getTexture( 1 ), getWindowBounds() );

    params::InterfaceGl::draw();
}