[SOLVED] Q RTT: How to set transparent color?

Problems building or running the engine, queries about how to use features etc.
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

[SOLVED] Q RTT: How to set transparent color?

Post by Van »

We are using the code supplied in the examples on rendering to texture (RTT). However, how do you set the transparency color? We would like to set it to "black".

If I remember correctly, the material script command is something like scene_blend colour_blend in the pass section. But how would one do it in code?
Last edited by Van on Fri May 05, 2006 10:21 pm, edited 1 time in total.
klauss
Hobgoblin
Posts: 559
Joined: Wed Oct 19, 2005 4:57 pm
Location: LS87, Buenos Aires, República Argentina.

Post by klauss »

Why don't you use a true transparent colour (Ogre::ColourValue(0,0,0,0)) as clear colour, and then render using alpha to it, and finally use alpha blend when rendering from the RTT?
Oíd mortales, el grito sagrado...
Hey! What is it with that that?
Wing Commander Universe
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Q RTT: How to set transparent color?

Post by xavier »

Van wrote: If I remember correctly, the material script command is something like scene_blend colour_blend in the pass section. But how would one do it in code?
pass->setSceneBlending()

Code: Select all

        void setSceneBlending( const SceneBlendType sbt );

    enum SceneBlendType
    {
        /// Make the object transparent based on the final alpha values in the texture
        SBT_TRANSPARENT_ALPHA,
        /// Make the object transparent based on the colour values in the texture (brighter = more opaque)
        SBT_TRANSPARENT_COLOUR,
        /// Add the texture values to the existing scene content
        SBT_ADD,
		/// Multiply the 2 colours together
		SBT_MODULATE,
        /// The default blend mode where source replaces destination
        SBT_REPLACE
        // TODO : more
    };
Available on Pass and Technique (the Technique method will apply to all contained passes).
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

Here go the links to the methods Xavier exposed:
Pass::setSceneBlending ()
Technique::setSceneBlending ()
Image
Van
Hobgoblin
Posts: 512
Joined: Fri Nov 19, 2004 3:56 am

Post by Van »

For those people in the future who find this:

Code: Select all


	// Load the Ogre Entity
	Ogre::Entity *mEntity = mSceneManager->createEntity( "Hud/SPS/VectorArrow", "vectorarrow.mesh" );

	// Create the Ogre SceneNode for the Entity
	mVectorArrowNode = mSceneManager->getRootSceneNode()->createChildSceneNode("HudSPSVectorArrowNode");
	mVectorArrowNode->attachObject( mEntity );
	mVectorArrowNode->setPosition( Ogre::Vector3::ZERO );
	mVectorArrowNode->setDirection( Ogre::Vector3::NEGATIVE_UNIT_Z );
	//mVectorArrowNode->setScale( 1.0f, 1.0f, 1.0f );
	mVectorArrowNode->setScale( 0.75f, 0.75f, 0.75f );
	mVectorArrowNode->setVisible( true );
	mVectorArrowNode->setFixedYawAxis( false );

	// Create an Ogre Render To Texture process.
	Ogre::RenderTexture *mRTT = mGlobalResource->OgreRoot->getRenderSystem()->createRenderTexture(
		"Hud/SPS/VectorArrow/RTT",
		128, 128,
		Ogre::TEX_TYPE_2D,
		Ogre::PF_B8G8R8A8 );	// <<< Note we use an ALPHA channel for transparency.

	// Create a camera to render from.
	Ogre::Camera *mRTTCam = mSceneManager->createCamera( "Hud/SPS/VectorArrow/Camera" );

	// Create a scene node to hold the camera.
	mVectorArrowCameraNode = mSceneManager->getRootSceneNode()->createChildSceneNode( "Hud/SPS/VectorArrow/CameraNode" );
	mVectorArrowCameraNode->attachObject( mRTTCam );
	mRTTCam->setPosition( Ogre::Vector3::ZERO );
	mRTTCam->setNearClipDistance( 0.5f );
	mRTTCam->setFarClipDistance( 100.0f );
	mRTTCam->setDirection( Ogre::Vector3::NEGATIVE_UNIT_Z );
	
	// Position the camera node just behind the subject node. Becarefull of the NearClip distance.
	mVectorArrowCameraNode->setPosition( 0.0f, 0.0f, 1.5f );
	mVectorArrowCameraNode->lookAt( Ogre::Vector3::ZERO, Ogre::Node::TS_WORLD, Ogre::Vector3::NEGATIVE_UNIT_Z );

	// Create a Ogre Viewport for the camera.
	Ogre::Viewport *mVP = mRTT->addViewport( mRTTCam );
	mVP->setOverlaysEnabled( false );
	mVP->setClearEveryFrame( true );
	mVP->setBackgroundColour( Ogre::ColourValue(0,0,0,0) );

	// Set the material as transparent ( Make sure RTT is set to Ogre::PF_B8G8R8A8 )
	Ogre:: MaterialPtr mMat = Ogre::MaterialManager::getSingleton().create(
		"Hud/SPS/VectorArrow/Resource", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); 
	mMat->setSceneBlending( Ogre::SceneBlendType::SBT_TRANSPARENT_COLOUR );

	// Create CEGUI texture from the Ogre RTT
	CEGUI::Texture *mTexture = mGlobalResource->CEGUIRenderer->createTexture( (CEGUI::utf8*)"Hud/SPS/VectorArrow/RTT" );

	// Create CEGUI Imageset
	CEGUI::Imageset *mRTTImageSet = CEGUI::ImagesetManager::getSingleton().createImageset( (CEGUI::utf8*)"Hud/SPS/VectorArrow/ImageSet", mTexture );
	
	// Define a CEGUI Image
	mRTTImageSet->defineImage( 
		(CEGUI::utf8*)"Hud/SPS/VectorArrow/Image", 
		CEGUI::Point( 0.0f, 0.0f ),
		CEGUI::Size( mTexture->getWidth(), mTexture->getHeight() ),
		CEGUI::Point( 0.0f, 0.0f ) );

	// Set the Image in the StaticImage widow.
	mSIVectorArrow->setImage( &mRTTImageSet->getImage( (CEGUI::utf8*)"Hud/SPS/VectorArrow/Image") );


OvermindDL1
Gnome
Posts: 333
Joined: Sun Sep 25, 2005 7:55 pm

Post by OvermindDL1 »

It will still get lost in the forums. You should wiki it.
hawkeye
Kobold
Posts: 30
Joined: Wed Mar 29, 2006 12:57 pm
Location: Netherlands

Post by hawkeye »

well, i found it, this looks a damn much like what im looking for, thnx :D