コード例 #1
0
void ShaderToyApp::resize()
{
	// Create/resize frame buffers (no multisampling)
	mBufferCurrent = gl::Fbo( getWindowWidth(), getWindowHeight() );
	mBufferNext = gl::Fbo( getWindowWidth(), getWindowHeight() );

	mBufferCurrent.getTexture().setFlipped(true);
	mBufferNext.getTexture().setFlipped(true);
}
コード例 #2
0
/* 
 * @Description: render SSAO now - woohoo!
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderSSAOToFBO()
{
	gl::setViewport( mSSAOMap.getBounds() );
	
	//render out main scene to FBO
	mSSAOMap.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mSSAOMap.getSize() );
	
	mRandomNoise.bind(1);
	mNormalDepthMap.getTexture().bind(2);
	
	mSSAOShader.bind();
	
	mSSAOShader.uniform("rnm", 1 );
	mSSAOShader.uniform("normalMap", 2 );
    
    //look at shader and see you can set these through the client if you so desire.
    //	mSSAOShader.uniform("rnm", 1 );
    //	mSSAOShader.uniform("normalMap", 2 );	
    //	mSSAOShader.uniform("totStrength", 1.38f);
    //	mSSAOShader.uniform("strength", 0.07f);
    //	mSSAOShader.uniform("offset", 10.0f);
    //	mSSAOShader.uniform("falloff", 0.2f);
    //	mSSAOShader.uniform("rad", 0.8f);
    
    //	mSSAOShader.uniform("rnm", 1 );
    //	mSSAOShader.uniform("normalMap", 2 );
    //	mSSAOShader.uniform("farClipDist", 20.0f);
    //	mSSAOShader.uniform("screenSizeWidth", (float)getWindowWidth());
    //	mSSAOShader.uniform("screenSizeHeight", (float)getWindowHeight());
	
    //	mSSAOShader.uniform("grandom", 1 );
    //	mSSAOShader.uniform("gnormals", 2 );
    //	mSSAOShader.uniform("gdepth", 1 );
    //	mSSAOShader.uniform("gdiffuse", 1 );
    
    gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	
	mSSAOShader.unbind();
	
	mNormalDepthMap.getTexture().unbind(2);
	mRandomNoise.unbind(1);
	
	mSSAOMap.unbindFramebuffer();
	
	gl::setViewport( getWindowBounds() );
}
コード例 #3
0
void FBOMultipleTargetsApp::draw()
{
	// clear the window to gray
	gl::clear( Color( 0.35f, 0.35f, 0.35f ) );

	// set the viewport to match our window
	gl::setViewport( getWindowBounds() );

	// draw the two textures we've created side-by-side
	gl::setMatricesWindow( getWindowSize() );
	gl::draw( mFbo.getTexture(0), mFbo.getTexture(0).getBounds() );
	gl::draw( mFbo.getTexture(1), mFbo.getTexture(1).getBounds() + Vec2f(mFbo.getTexture(0).getWidth(),0) );
}
コード例 #4
0
void GroupingApp::setup() {
	fbo = gl::Fbo(getWindowWidth(), getWindowHeight());
	
	gui = new SimpleGUI(this, Font(loadResource(RES_SGUI_FONT), 8));
	gui->lightColor = ColorA(1, 1, 0, 1);	
	gui->addColumn();
	gui->addLabel("CONTROLS");
	gui->addParam("Rotation", &rotation, 0, 360, 0);
	gui->addParam("Size", &size, 100, 600, 200); 	
	gui->addParam("Color", &color, ColorA(0,0.5,1,0.5), SimpleGUI::RGB); //use R,G,B,A sliders
	gui->addColumn();	
	gui->addLabel("RENDER TYPE");
	gui->addParam("Fill", &fill, true, RENDER_TYPE_GROUP); //if we specify group id, we create radio button set
	gui->addParam("Stroke", &stroke, false, RENDER_TYPE_GROUP); //i.e. only one of the buttons can be active at any time	
	strokePanel = gui->addPanel();
	gui->addParam("Thickness", &thickness, 1, 10);
	gui->addColumn();
	gui->addLabel("OPTIONS");
	gui->addParam("Auto Rotation", &autoRotation, false); 	
	gui->addColumn();
	gui->addLabel("PREVIEW");
	gui->addParam("PreviewTex", &fbo.getTexture()); 	
	
	gui->load(CONFIG_FILE); //we load settings after specifying all the 
	//params because we need to know their name and type
	
	timer.start();
	prevTime = timer.getSeconds();
	
	
}
コード例 #5
0
ファイル: MemExploreApp.cpp プロジェクト: imclab/memdescent
void MemExploreApp::draw()
{
  mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim);
  mTexture.setWrap(GL_REPEAT, GL_REPEAT);
  mTexture.setMinFilter(GL_NEAREST);
  mTexture.setMagFilter(GL_NEAREST);
  
  float frustum[6];
  mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]);

  mFbo.bindFramebuffer();
  gl::setMatricesWindow(mFbo.getSize(), false);

  mProgram.bind();
  mProgram.uniform("uTexture", 0);
  mProgram.uniform("uVolumeDim", mVolumeDim);
  mProgram.uniform("uTilesDim", mTilesDim);
  mProgram.uniform("uTime", (float)getElapsedSeconds());
  mProgram.uniform("uEyePoint", mCamera.getEyePoint());
  mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis());
  mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis());
  mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip());
  mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized());
  mProgram.uniform("uAspectRatio", mCamera.getAspectRatio());
  mTexture.enableAndBind();
  gl::drawSolidRect(mFbo.getBounds());
  mTexture.unbind();
  mProgram.unbind();
  
  mFbo.unbindFramebuffer();
  
  gl::setMatricesWindow(getWindowSize());
  gl::draw(mFbo.getTexture(), getWindowBounds());
}
コード例 #6
0
void RepulsionApp::setFboVelocities( gl::Fbo &fbo )
{
	Surface32f vel( fbo.getTexture() );
	Surface32f::Iter it = vel.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = Rand::randVec3f() * 0.1f;
			it.r() = 0.0f;//r.x;
			it.g() = 0.0f;//r.y;
			it.b() = 0.0f;//r.z;
			it.a() = 0.0f;
		}
	}
	
	gl::Texture velTexture( vel );
	velTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mVelInitShader.bind();
	mVelInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mVelInitShader.unbind();
	fbo.unbindFramebuffer();
}
コード例 #7
0
ファイル: LEDCamApp.cpp プロジェクト: controlgroup/LEDCam
void LEDCamApp::draw()
{
	// clear out the window with black
	gl::clear( kClearColor ); 
	
	if( !mTexture ) return;
	mFbo.bindFramebuffer();
	mTexture.enableAndBind();
	mShader.bind();
	float aspect = kWindowHeight/kWindowWidth;
	cout << "Aspect: " << aspect << " \n";
	mShader.uniform( "aspect", aspect );
	mShader.uniform( "tex", 0 );
	mShader.uniform( "bright", 3.0f );
	mShader.uniform( "spacing", 3 );
	mShader.uniform( "ledCount", 100.0f );
	gl::drawSolidRect( getWindowBounds() );
	mTexture.unbind();
	mShader.unbind();
	mFbo.unbindFramebuffer();
	
	gl::Texture fboTexture = mFbo.getTexture();
	fboTexture.setFlipped();
	gl::draw( fboTexture );

}
コード例 #8
0
ファイル: FBOBasicApp.cpp プロジェクト: AKS2346/Cinder
void FBOBasicApp::draw()
{
	// clear the window to gray
	gl::clear( Color( 0.35f, 0.35f, 0.35f ) );

	// setup our camera to render the cube
	CameraPersp cam( getWindowWidth(), getWindowHeight(), 60.0f );
	cam.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );
	cam.lookAt( Vec3f( 2.6f, 1.6f, -2.6f ), Vec3f::zero() );
	gl::setMatrices( cam );

	// set the viewport to match our window
	gl::setViewport( getWindowBounds() );

	// use the scene we rendered into the FBO as a texture
	glEnable( GL_TEXTURE_2D );
	mFbo.bindTexture();

	// draw a cube textured with the FBO
	gl::color( Color::white() );
	gl::drawCube( Vec3f::zero(), Vec3f( 2.2f, 2.2f, 2.2f ) );

	// show the FBO texture in the upper left corner
	gl::setMatricesWindow( getWindowSize() );
	gl::draw( mFbo.getTexture(0), Rectf( 0, 0, 96, 96 ) );
	
#if ! defined( CINDER_GLES ) // OpenGL ES can't do depth textures, otherwise draw the FBO's
	gl::draw( mFbo.getDepthTexture(), Rectf( 96, 0, 96 + 96, 96 ) );
#endif
}
コード例 #9
0
void StereoscopicRenderingApp::renderAnaglyph(  const Vec2i &size, const ColorA &left, const ColorA &right )
{	
	// bind the FBO and clear its buffer
	mFbo.bindFramebuffer();
	gl::clear( mColorBackground );

	// render the scene using the side-by-side technique
	renderSideBySide( mFbo.getSize() );

	// unbind the FBO
	mFbo.unbindFramebuffer();

	// enable the anaglyph shader
	mShaderAnaglyph.bind();
	mShaderAnaglyph.uniform( "tex0", 0 );
	mShaderAnaglyph.uniform( "clr_left", left );
	mShaderAnaglyph.uniform( "clr_right", right );	

	// bind the FBO texture and draw a full screen rectangle,
	// which conveniently is exactly what the following line does
	gl::draw( mFbo.getTexture(), Rectf(0, float(size.y), float(size.x), 0) );

	// disable the anaglyph shader
	mShaderAnaglyph.unbind();
}
コード例 #10
0
void CatalogApp::setFboPositions( gl::Fbo &fbo )
{
	int numBrightStars = mBrightStars.size();

	int index = 0;
	
	Surface32f posSurface( fbo.getTexture() );
	Surface32f::Iter it = posSurface.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f pos = Vec3f( 1000000.0f, 0.0f, 0.0f );
			float col = 0.4f;
			float rad = 0.0f;
			if( index < numBrightStars ){
				pos = mBrightStars[index]->mPos;
				col = mBrightStars[index]->mColor;
				rad = floor( constrain( ( ( 6.0f - ( mBrightStars[index]->mAbsoluteMag ) )/6.0f ), 0.3f, 1.0f ) * 3.0f * 1000 );
			}
			it.r() = pos.x;
			it.g() = pos.y;
			it.b() = pos.z;
			it.a() = rad + col;

			index ++;
		}
	}

	gl::Texture posTexture( posSurface );
	fbo.bindFramebuffer();
	gl::setMatricesWindow( fbo.getSize(), false );
	gl::setViewport( fbo.getBounds() );
	gl::clear( ColorA( 0, 0, 0, 0 ), true );
	gl::draw( posTexture );
	fbo.unbindFramebuffer();
}
コード例 #11
0
void StereoscopicRenderingApp::renderInterlacedHorizontal( const Vec2i &size )
{
	// bind the FBO and clear its buffer
	mFbo.bindFramebuffer();
	gl::clear( mColorBackground );

	// render the scene using the over-under technique
	renderOverUnder( mFbo.getSize() );

	// unbind the FBO
	mFbo.unbindFramebuffer();

	// enable the interlace shader
	mShaderInterlaced.bind();
	mShaderInterlaced.uniform( "tex0", 0 );
	mShaderInterlaced.uniform( "window_origin", Vec2f( getWindowPos() ) );
	mShaderInterlaced.uniform( "window_size", Vec2f( getWindowSize() ) );

	// bind the FBO texture and draw a full screen rectangle,
	// which conveniently is exactly what the following line does
	gl::draw( mFbo.getTexture(), Rectf(0, float(size.y), float(size.x), 0) );

	// disable the interlace shader
	mShaderInterlaced.unbind();
}
コード例 #12
0
/* 
 * @Description: need to blur[the SSAO texture] horizonatally then vertically (for shader performance reasons). Called ping-ponging as it one FBO drawn to another
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::pingPongBlur()
{
	//render horizontal blue first
	gl::setViewport( mPingPongBlurH.getBounds() );
	
	mPingPongBlurH.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mPingPongBlurH.getSize() );
	
	mSSAOMap.getTexture().bind(0);
	mHBlurShader.bind();
	mHBlurShader.uniform("RTScene", 0);
    gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	mHBlurShader.unbind();
	mSSAOMap.getTexture().unbind(0);
	
	mPingPongBlurH.unbindFramebuffer();
	
	//gl::setViewport( getWindowBounds() ); //redundant
	
	//now render vertical blur
	gl::setViewport( mPingPongBlurV.getBounds() );
	
	mPingPongBlurV.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mPingPongBlurV.getSize() );
	
	mPingPongBlurH.getTexture().bind(0);
	mHBlurShader.bind();
	mHBlurShader.uniform("RTBlurH", 0);
	gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	mHBlurShader.unbind();
	mPingPongBlurH.getTexture().unbind(0);
	
	mPingPongBlurV.unbindFramebuffer();
	
	gl::setViewport( getWindowBounds() );
}
コード例 #13
0
ファイル: syphonImpApp.cpp プロジェクト: sloev/cindersketches
void syphonImpApp::draw()
{
	gl::enableAlphaBlending();
	gl::clear( Color( 0.1f, 0.1f, 0.1f ) );

    renderSceneToFbo();
    mTextureSyphon.publishTexture(&myFbo.getTexture()); //publish our texture

    Vec2f upperLeftCorner = Vec2f( 0, WIDTH );
    Vec2f lowerRightCorner = Vec2f(WIDTH,WIDTH-(WIDTH/1.33) );
    Rectf rect = Rectf( upperLeftCorner, lowerRightCorner );
    gl::draw( myFbo.getTexture(0),rect);


	

}
コード例 #14
0
void Narcotic::draw()
{
	
	gl::clear();
	fboProjection.bindFramebuffer();
	gl::clear(Color::gray(0.25));
	v1.draw();
	fboProjection.unbindFramebuffer();
	gl::draw(fboProjection.getTexture(), Rectf(projectionWindow->getBounds()));
	//fboProjection.unbindTexture();
}
コード例 #15
0
void SmoothDisplacementMappingApp::renderNormalMap()
{
	if( mNormalMapShader && mNormalMapFbo ) 
	{
		mNormalMapFbo.bindFramebuffer();
		{
			// setup viewport and matrices 
			glPushAttrib( GL_VIEWPORT_BIT );
			gl::setViewport( mNormalMapFbo.getBounds() );

			gl::pushMatrices();
			gl::setMatricesWindow( mNormalMapFbo.getSize(), false );

			// clear the color buffer
			gl::clear();			

			// bind the displacement map
			mDispMapFbo.getTexture().bind(0);

			// render the normal map
			mNormalMapShader.bind();
			mNormalMapShader.uniform( "texture", 0 );
			mNormalMapShader.uniform( "amplitude", 4.0f );

			Area bounds = mNormalMapFbo.getBounds(); //bounds.expand(-1, -1);
			gl::drawSolidRect( bounds );

			mNormalMapShader.unbind();

			// clean up after ourselves
			mDispMapFbo.getTexture().unbind();

			gl::popMatrices();

			glPopAttrib();
		}
		mNormalMapFbo.unbindFramebuffer();
	}
}
コード例 #16
0
void GroupingApp::draw() {
	float currTime = timer.getSeconds();
	float deltaTime = currTime - prevTime;
	prevTime = currTime;
	
	if (autoRotation) {
		rotation += deltaTime * 60;
		rotation = fmod(rotation, 360);
	}
	
	fbo.bindFramebuffer();
	
	gl::pushMatrices();
	gl::clear(ColorA(0.2, 0.2, 0.2, 1.0));
	gl::translate(Vec2f(getWindowWidth()/2, getWindowHeight()/2));
	gl::rotate(rotation);
	gl::color(color);
	gl::enableAlphaBlending();
	gl::disableDepthRead();
	
	if (fill) {
		gl::translate(Vec2f(-50, -50));
		gl::drawSolidRect(Rectf(-size/2, -size/2, size/2, size/2));
		gl::translate(Vec2f(+100, +100));
		gl::drawSolidRect(Rectf(-size/2, -size/2, size/2, size/2));
	}
	else if (stroke) {
		glLineWidth(thickness);
		gl::translate(Vec2f(-50, -50));
		gl::drawLine(Vec2f(-size/2, -size/2), Vec2f( size/2, -size/2));
		gl::drawLine(Vec2f( size/2, -size/2), Vec2f( size/2,  size/2));
		gl::drawLine(Vec2f( size/2,  size/2), Vec2f(-size/2,  size/2));
		gl::drawLine(Vec2f(-size/2,  size/2), Vec2f(-size/2, -size/2));		
		gl::translate(Vec2f(+100, +100));
		gl::drawLine(Vec2f(-size/2, -size/2), Vec2f( size/2, -size/2));
		gl::drawLine(Vec2f( size/2, -size/2), Vec2f( size/2,  size/2));
		gl::drawLine(Vec2f( size/2,  size/2), Vec2f(-size/2,  size/2));
		gl::drawLine(Vec2f(-size/2,  size/2), Vec2f(-size/2, -size/2));
		glLineWidth(1);
	}
	gl::popMatrices();	
	
	fbo.unbindFramebuffer();
	
	gl::color(ColorA(1,1,1,1));
	gl::draw(fbo.getTexture());
	
	strokePanel->enabled = stroke ? true : false;
	gui->draw();
}
コード例 #17
0
ファイル: StarsApp.cpp プロジェクト: rmnzr/Cinder-Samples
void StarsApp::createFbo()
{
	// determine the size of the frame buffer
	int w = getWindowWidth() * 2;
	int h = getWindowHeight() * 2;

	if( mFbo && mFbo.getSize() == Vec2i(w, h) )
		return;

	// create the FBO
	gl::Fbo::Format fmt;
	fmt.setWrap( GL_REPEAT, GL_CLAMP_TO_BORDER );
	
	mFbo = gl::Fbo( w, h, fmt );

	// work-around for the flipped texture issue
	mFbo.getTexture().setFlipped();
	mFbo.getDepthTexture().setFlipped();
}
コード例 #18
0
void	KinectEcard::snapshot(){
	gl::Fbo fbo( 640, 480, false );

	// render stored depth FBO
	fbo.bindFramebuffer();
	gl::pushMatrices();
		gl::clear( Color::black() );
		gl::color( Color::white() );
		gl::setMatricesWindowPersp( fbo.getSize() );

		mDepthCompareShader.bind();

		mDepthCompareShader.uniform( "tex0", 0 );
		mDepthCompareShader.uniform( "tex1", 1 );

		mDepthFbo.bindTexture(0);
		mStoredDepthFbo.bindTexture(1);

		gl::translate( 0, 480 );
		gl::scale( 1, -1 );

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

		mDepthCompareShader.unbind();
	gl::popMatrices();
	fbo.unbindFramebuffer();

	// save stored depth fbo
	fbo.blitTo( mStoredDepthFbo, fbo.getBounds(), mStoredDepthFbo.getBounds() );

	// render substracted video fbo
	fbo.bindFramebuffer();
	gl::pushMatrices();
		gl::clear( Color::black() );
		gl::color( Color::white() );
		gl::setMatricesWindowPersp( mSubstractedVideoFbo.getSize() );
		gl::draw( mSubstractedVideoFbo.getTexture() );
	gl::popMatrices();
	fbo.unbindFramebuffer();

	// save it
	fbo.blitTo( mStoredVideoFbo, fbo.getBounds(), mStoredVideoFbo.getBounds() );
}
コード例 #19
0
ファイル: ardroneApp.cpp プロジェクト: eighteight/CinderEight
void ardroneApp::draw()
{
    renderFbo.bindFramebuffer();

	gl::clear( Color( 0, 0, 0 ) );
    gl::color( Color::white() );
	if ( mFrameTexture ) {
		Rectf centeredRect = Rectf( mFrameTexture.getBounds() ).getCenteredFit( getWindowBounds(), true );
		gl::draw( mFrameTexture, centeredRect  );
	}
    
    renderFbo.blitToScreen(renderFbo.getBounds(), getWindowBounds());
    mSyphonServer.publishTexture(renderFbo.getTexture(), false);

    renderFbo.unbindFramebuffer(); // return rendering to the window's own frame buffer

	if( mInfoTexture ) {
		glDisable( GL_TEXTURE_RECTANGLE_ARB );
		gl::draw( mInfoTexture, Vec2f( 5, getWindowHeight() - 5 - mInfoTexture.getHeight() ) );
	}
}
コード例 #20
0
void ___PACKAGENAMEASIDENTIFIER___App::draw()
{
	// clear out the window with black
	gl::clear( kClearColor ); 
	
	if( !mTexture ) return;
	mFbo.bindFramebuffer();
	mTexture.enableAndBind();
	mShader.bind();
	mShader.uniform( "tex", 0 );
	mShader.uniform( "mixColor", Vec3d( mMixColorRed, mMixColorGreen, mMixColorBlue ) );
	gl::drawSolidRect( getWindowBounds() );
	mTexture.unbind();
	mShader.unbind();
	mFbo.unbindFramebuffer();
	
	gl::Texture fboTexture = mFbo.getTexture();
	fboTexture.setFlipped();
	gl::draw( fboTexture );

	params::InterfaceGl::draw();
}
コード例 #21
0
void ScreenShadersApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	
	// bind the Fbo
	mFbo.bindFramebuffer();
	// match the viewport to the Fbo dimensions
	gl::setViewport( mFbo.getBounds() );
	// setup an ortho projection
	gl::setMatricesWindow( mFbo.getWidth(), mFbo.getHeight() );
	// clear the Fbo
	gl::clear( Color( 0, 0, 0 ) );
	
	if ( mTexture ) {
		gl::draw( mTexture );
	}
	
	// unbind the Fbo
	mFbo.unbindFramebuffer();
	
	gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
	
	float kernelRes = 21.0f;
	
	mBlurShader.bind();
	mBlurShader.uniform( "kernelRes", kernelRes );
	mBlurShader.uniform( "invKernelRes", 1.0f / kernelRes );
	mBlurShader.uniform( "fboTex", 0 );
	mBlurShader.uniform( "kernelTex", 1 );
	mBlurShader.uniform( "orientationVector", Vec2f( 1.0f, 1.0f ) );
	mBlurShader.uniform( "blurAmt", 1.0f );
	mBlurShader.uniform( "colMulti", 1.0f );
	
	mBlurKernel.bind( 1 );
	
	gl::draw( mFbo.getTexture(0), Rectf( 0, getWindowHeight(), getWindowWidth(), 0 ) );
	mBlurShader.unbind();
}
コード例 #22
0
void HiKinectApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
	
	gl::disableDepthWrite();
	gl::disableDepthRead();
	
	if (mDoNormalMap) {
		generateNormalMap();
		gl::setViewport( getWindowBounds() );
		gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
		gl::draw( mFbo.getTexture(0), Rectf( 0, getWindowHeight(), getWindowWidth(), 0 ) );
	}
	
	
	gl::enableDepthWrite();
	gl::enableDepthRead();
	
	draw3D();
	
	params::InterfaceGl::draw();
}
コード例 #23
0
void RepulsionApp::setFboPositions( gl::Fbo &fbo )
{
	Surface32f pos( fbo.getTexture() );
	Surface32f::Iter it = pos.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = mRoom.getRandRoomPos();
			float mass = Rand::randFloat( 20.0f, 30.0f );
			if( Rand::randFloat() < 0.05f ) 
				mass = Rand::randFloat( 50.0f, 60.0f );
			
			if( it.y() < 5  && it.x() < 50 )
				mass = Rand::randFloat( 300.0f, 5000.0f );
			else
				mass = Rand::randFloat( 50.0f, 300.0f );
			
			it.r() = r.x;
			it.g() = r.y;
			it.b() = r.z;
			it.a() = 100.0f;
		}
	}
	
	gl::Texture posTexture( pos );
	posTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mPosInitShader.bind();
	mPosInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mPosInitShader.unbind();
	fbo.unbindFramebuffer();
}
コード例 #24
0
ファイル: ChargesApp.cpp プロジェクト: gaborpapp/apps
void ChargesApp::draw()
{
	mFbo.bindFramebuffer();
	gl::setViewport( mFbo.getBounds() );
	gl::setMatricesWindow( mFbo.getSize() );

	gl::clear( Color::black() );
	mEffectCharge.setLineWidth( mLineWidth );
	mEffectCharge.draw();

	mFbo.unbindFramebuffer();

	gl::color( Color::white() );
	gl::Texture output = mKawaseBloom.process( mFbo.getTexture(), 8, mBloomStrength );

	gl::setViewport( getWindowBounds() );
	gl::setMatricesWindow( getWindowSize() );

	gl::clear( Color::black() );
	gl::color( Color::white() );
	gl::draw( output, getWindowBounds() );

	mndl::kit::params::PInterfaceGl::draw();
}
コード例 #25
0
// Draw
void PixarDemo2012::draw()
{

    gl::clear( ColorA(0.0f,0.0f,0.0f,1.0f) );

    //render Gradient FBO
    if(!drawMindField && !drawCloth)
    {
        renderGradientFBO();
    }

    gl::setViewport( getWindowBounds() );
    gl::setMatricesWindow( getWindowSize(), true );

    gl::clear( ColorA(0.0f,0.0f,0.0f,1.0f) );

    // draw FBO bg
    gl::color(1.0f,1.0f,1.0f);
    gl::draw( mGradientFBO.getTexture(0), Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );

    if ( drawTitle ) {
        if ( mTime > 10.0f ) drawTitle = false;
        theTitle.Render();
    }


    // FFT stuff
    generateWaveforms();

    if ( drawMindField ) {
        theMindField.Render();
        drawFader();
        return;
    }
    if ( drawCubes ) {
        gl::popMatrices();
        gl::setMatrices( theCubes.cubesCamera );
        theCubes.Render();
    }
    if ( drawCloth ) {

        theCloth.Render();
        drawFader();
        return;
    }


    // Balls
    if ( !drawCubes ) {
        gl::setMatricesWindow( getWindowSize(), true );
        if (makeBall > 0.075f) mParticleController.addParticles(1,makeBall*100.0f,mTime);
        mParticleController.draw();
    }
    if ( drawFPS ) {
        string mString;
        mString = str(boost::format("FRAMERATE: %f") % getAverageFps() );
        gl::drawString( mString, Vec2f( 10.0f, 10.0f ), Color::white(), mFont );
    }

    drawFader();

}
コード例 #26
0
void KinectEcard::draw()
{
	gl::clear( Color::black() );
	gl::color( Color::white() );

	//
	gl::setViewport( app::getWindowBounds() );

	// draw FBO's
	gl::pushMatrices();
	{
		// draw video stream and info string
		gl::pushMatrices();
			mVideoFbo.getTexture().setFlipped();
			gl::draw( mVideoFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Video stream ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		gl::pushMatrices();
			gl::translate( mVideoFbo.getWidth(), 0 );
			mDepthFbo.getTexture().setFlipped();
			gl::draw( mDepthFbo.getTexture() );

				gl::pushMatrices();
					gl::enableAlphaBlending();
					gl::drawString( "Depth stream ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
					gl::disableAlphaBlending();
				gl::popMatrices();
			gl::popMatrices();
		gl::popMatrices();
		
		gl::pushMatrices();
			gl::translate( 0, mVideoFbo.getHeight() );
			gl::draw( mSubstractedVideoFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Result ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		gl::pushMatrices();
			gl::translate( mVideoFbo.getWidth(), mVideoFbo.getHeight() );
			mStoredDepthFbo.getTexture().setFlipped();
			gl::draw( mStoredDepthFbo.getTexture() );

			gl::pushMatrices();
				gl::enableAlphaBlending();
				gl::drawString( "Stored depth buffer ", Vec2f( 20, 10 ), ColorA::black(), Font( "Arial", 40 )  );
				gl::disableAlphaBlending();
			gl::popMatrices();
		gl::popMatrices();

		if( mDrawDepthCorrectionMap ){
			gl::pushMatrices();
			{
				gl::scale( 0.25f, 0.25f );
				gl::draw( mCorrectionMap );
			}
			gl::popMatrices();
		}
	}
	gl::popMatrices();

	// draw bounderies for niceness
	gl::pushMatrices();
		gl::color( ColorA::black() );
		gl::drawLine( Vec3i( 0, mVideoFbo.getHeight(), 0 ), Vec3i( mVideoFbo.getWidth()*2, mVideoFbo.getHeight(), 0 ) );
		gl::drawLine( Vec3i( mVideoFbo.getWidth(), 0, 0 ), Vec3i( mVideoFbo.getWidth(), mVideoFbo.getHeight()*2, 0 ) );
	gl::popMatrices();

	mParams.draw();
}
コード例 #27
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();
}
コード例 #28
0
ファイル: StarsApp.cpp プロジェクト: rmnzr/Cinder-Samples
void StarsApp::draw()
{		
	int w = getWindowWidth();
	int h = getWindowHeight();

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

	if(mIsStereoscopic) {
		glPushAttrib( GL_VIEWPORT_BIT );
		gl::pushMatrices();

		// render left eye
		mCamera.enableStereoLeft();

		gl::setViewport( Area(0, 0, w / 2, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		// render right eye
		mCamera.enableStereoRight();

		gl::setViewport( Area(w / 2, 0, w, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		gl::popMatrices();		
		glPopAttrib();
	}
	else if(mIsCylindrical) {
		// make sure we have a frame buffer to render to
		createFbo();

		// determine correct aspect ratio and vertical field of view for each of the 3 views
		w = mFbo.getWidth() / 3;
		h = mFbo.getHeight();

		const float aspect = float(w) / float(h);
		const float hFoV = 60.0f;
		const float vFoV = toDegrees( 2.0f * math<float>::atan( math<float>::tan( toRadians(hFoV) * 0.5f ) / aspect ) );

		// for values smaller than 1.0, this will cause each view to overlap the other ones
		const float overlap = 1.0f;	

		// bind the frame buffer object
		mFbo.bindFramebuffer();

		// store viewport, camera and matrices, so we can restore later
		glPushAttrib( GL_VIEWPORT_BIT );
		CameraStereo original = mCamera.getCamera();
		gl::pushMatrices();

		// setup camera	
		CameraStereo cam = mCamera.getCamera();
		cam.disableStereo();
		cam.setAspectRatio(aspect);
		cam.setFov( vFoV );

		Vec3f right, up;	
		cam.getBillboardVectors(&right, &up);
		Vec3f forward = up.cross(right);

		// render left side
		gl::setViewport( Area(0, 0, w, h) );

		cam.setViewDirection( Quatf(up, overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// render front side
		gl::setViewport( Area(w, 0, w*2, h) );

		cam.setViewDirection( forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();	
	
		// draw user interface
		mUserInterface.draw( (boost::format("Cylindrical Projection (%d degrees)") % int( (1.0f + 2.0f * overlap) * hFoV ) ).str() );

		// render right side
		gl::setViewport( Area(w*2, 0, w*3, h) );

		cam.setViewDirection( Quatf(up, -overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// unbind the frame buffer object
		mFbo.unbindFramebuffer();

		// restore states
		gl::popMatrices();		
		mCamera.setCurrentCam(original);
		glPopAttrib();

		// draw frame buffer and perform cylindrical projection using a fragment shader
		if(mShader) {
			float sides = 3;
			float radians = sides * toRadians( hFoV );
			float reciprocal = 0.5f / sides;

			mShader.bind();
			mShader.uniform("texture", 0);
			mShader.uniform("sides", sides);
			mShader.uniform("radians", radians );
			mShader.uniform("reciprocal", reciprocal );
		}

		Rectf centered = Rectf(mFbo.getBounds()).getCenteredFit( getWindowBounds(), false );
		gl::draw( mFbo.getTexture(), centered );

		if(mShader) mShader.unbind();
	}
	else {
		mCamera.disableStereo();

		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		render();
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw("Perspective Projection");
	}

	// fade in at start of application
	gl::enableAlphaBlending();
	double t = math<double>::clamp( mTimer.getSeconds() / 3.0, 0.0, 1.0 );
	float a = ci::lerp<float>(1.0f, 0.0f, (float) t);

	if( a > 0.0f ) {
		gl::color( ColorA(0,0,0,a) );
		gl::drawSolidRect( getWindowBounds() );
	}
	gl::disableAlphaBlending();
}
コード例 #29
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();
}
コード例 #30
0
ファイル: GlowTestApp.cpp プロジェクト: synthresin/GlowTest
void GlowTestApp::draw()
{
    // clear out the window with black

    gl::clear( Color( 0, 0, 0 ) );


    // 일단 Fbo 를 하나 만들어서 그린다. 드로잉 컨텍스트가 완전 새로운게 되는듯? Fbo 에 대해 더 공부해볼 필요가 있당...
    // 뭔가 카메라 설정도 마구마구 해서

    mNormalFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::color(1.0, 1.0, 1.0);
    gl::drawSphere(Vec3f(200,100, 0), 50.0);
    gl::drawSphere(Vec3f(500,100, 0), 50.0);
    mNormalFbo.unbindFramebuffer();






    // 블러 때리는용 Fbo 를 만들어서 또 그린다. (지금은 그냥 오리지널만 써도 될듯.)

    mGlowFbo.bindFramebuffer();
    gl::setMatricesWindowPersp(getWindowSize());
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::color(0.4, 0.2, 0.5);
    gl::drawSphere(Vec3f(200,100, 0), 50.0);


    mGlowFbo.unbindFramebuffer();


    // 텍스쳐 블러시킬 Fbo 를 만든다. 텍스쳐가 정면에 나와야 되니까 카메라 세팅을 신더 기본으로 해준다.
    // 블러 때리는용 Fbo 를 텍스쳐화 시켜 그린다.
    mBlurFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );

    gl::setMatricesWindowPersp(getWindowSize());

    mGlowFbo.getTexture().bind(1);  // 얘를 바인딩 해야한다. 그래서 sampler 로 전달하구, 텍스쳐로 그려내야돼.
    mBlurShader.bind();
    mBlurShader.uniform("GlowFboTex", 1);   // glowfbo 를 전사한 텍스쳐를 sampler1d 로 보낸다.
    mBlurShader.uniform("sampleOffset", Vec2f(0.7, 0.3) * ( 3.0f / getWindowWidth() ) );

    gl::drawSolidRect( Rectf(0.0, 0.0, getWindowWidth(), getWindowHeight() ) );
    mBlurShader.unbind();
    mGlowFbo.getTexture().unbind();
    mBlurFbo.unbindFramebuffer();

    //  섞어보자.


    mMultiplyFbo.bindFramebuffer();
    gl::clear( ColorA(0, 0, 0, 0 ) );
    gl::setMatricesWindowPersp(getWindowSize());

    // 두가지 합칠 소스 가져오기
    mNormalFbo.getTexture().bind(1);
    mBlurFbo.getTexture().bind(2);


    mMultiShader.bind();
    mMultiShader.uniform("Tex1", 1);
    mMultiShader.uniform("Tex2", 2);
    gl::drawSolidRect( Rectf(0.0, 0.0, getWindowWidth(), getWindowHeight() ) );
    mMultiShader.unbind();
    mMultiplyFbo.unbindFramebuffer();

    // 최종적으로 블러된 Fbo 를 전사한다.


    //gl::draw(mMultiplyFbo.getTexture());


    // 뒤집힘 해결 테스트

    gl::drawSphere(Vec3f(200,100, 0), 50.0);
    gl::drawSphere(Vec3f(500,100, 0), 50.0);

    gl::draw(mNormalFbo.getTexture());


}