Exemplo n.º 1
0
void MeshViewApp::draw()
{
	// Clear the window
	gl::clear();
	gl::color(Color::white());

	if(isInitialized())
	{
		// Get ready to draw in 3D
		gl::pushMatrices();
		gl::setMatrices(m_camera);

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

		// Bind textures
		if(m_texDiffuse)
			m_texDiffuse->enableAndBind();

		if (m_texNormal)
			m_texNormal->bind(1);

		if (m_texSpecular)
			m_texSpecular->bind(2);

		if(m_texAO)
			m_texAO->bind(3);

		if(m_texEmissive)
			m_texEmissive->bind(4);

		// Bind shader
		m_shader->bind();
		m_shader->uniform("texDiffuse", 0);
		m_shader->uniform("texNormal", 1);
		m_shader->uniform("texSpecular", 2);
		m_shader->uniform("texAO", 3);
		m_shader->uniform("texEmissive", 4);
		m_shader->uniform("texDiffusePower", m_texDiffusePower);
		m_shader->uniform("texNormalPower", m_texNormalPower);
		m_shader->uniform("texSpecularPower", m_texSpecularPower);
		m_shader->uniform("texAOPower", m_texAOPower);
		m_shader->uniform("texEmissivePower", m_texEmissivePower);
		m_shader->uniform("diffuseEnabled", m_diffuseEnabled);
		m_shader->uniform("normalEnabled", m_normalEnabled);
		m_shader->uniform("specularEnabled", m_specularEnabled);
		m_shader->uniform("aoEnabled", m_aoEnabled);
		m_shader->uniform("emissiveEnabled", m_emissiveEnabled);

		m_shader->uniform("material.Ka", m_matAmbient);
		m_shader->uniform("material.Kd", m_matDiffuse);
		m_shader->uniform("material.Ks", m_matSpecular);
		m_shader->uniform("material.Shininess", m_matShininess);
		m_shader->uniform("gamma", m_gamma);

		// Enable lights
		m_light1->enable();
		m_light2->enable();

		// Render model
		gl::pushModelView();
		gl::multModelView(m_matrix);
		m_assimpLoader.draw();
		gl::popModelView();

		// Disable lights
		m_light1->disable();
		m_light2->disable();

		// Unbind shader
		m_shader->unbind();

		// Unbind textures
		gl::disable(m_texDiffuse->getTarget());

		// Disable 3D rendering
		gl::disableDepthWrite();
		gl::disableDepthRead();

		// Restore matrices
		gl::popMatrices();

		// Enable 2D rendering
		gl::setMatricesWindow(getWindowSize());
		gl::setViewport(getWindowBounds());

		// Render parameter window
		if(m_params)
			m_params->draw();
	}

	// Render debug information
	Debug::get().draw(ColorAf::white());
}
Exemplo n.º 2
0
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();
}