Render To Texture

Forum for general chit-chat or off-topic discussion.

Moderators: CEGUI MVP, CEGUI Team

singbol
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Sun Aug 23, 2009 04:44

Render To Texture

Postby singbol » Tue Sep 22, 2009 07:23

Hi,
I've finished render the 3d scene to GUI(StaticImage here),the problem I encountered is that I just want to render my player to the StaticImage, but what I get is that my player and black background altogher are rendered to the StaticImage, which lead to a black square(the dimension of StaticImage) who takes the player.What I want is just a player rendered at the StaticImage area, the remain pixel of the StaticImage is transparent, from this we can see the background image.
My Layout likes follow:
////////////////////////////////////////////////////////////////
//....................................................................................//
//....................................................................................//
//....................................................................................//
//....................................................................................//
//..........Background Image occupy the full game area......................//
//....................................................................................//
//....................................................................................//
//...///StaticImage/////........................................................//
//...//...................//........................................................//
//...//..Player..........//........................................................//
//...//...................//........................................................//
//...//...................//........................................................//
//...//////////////////........................................................//
////////////////////////////////////////////////////////////////
Player shouldn't occupy all of the StaticImage area, the other pixels of StaitcImage should be Background Image

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Render To Texture

Postby CrazyEddie » Tue Sep 22, 2009 09:07

Did you disable the StaticImage background by setting the "BackgroundEnabled" property to "False"? If so the background is coming from the texture you're using as the source of the image. Make sure you clear the alpha values on that texture to 0 before you render :)

CE.

singbol
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Sun Aug 23, 2009 04:44

Re: Render To Texture

Postby singbol » Tue Sep 22, 2009 09:21

I've disabled "FrameEnabled" and "BackgroundEnabled" property, code I used to render to texture is from the ogre's tutorial, I don't know how and where to clear the alpha component of the source image.
My Code Here:

Code: Select all

  // Setup Render To Texture for preview window
          TexturePtr rttTex = TextureManager::getSingleton().createManual(m_RttTexName,
             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
             512, 512, 1, 0, PF_R8G8B8A8, TU_RENDERTARGET);
            {
             if (!m_pCamera)
             {
                m_randerCamera = TRUE;
                 m_pCamera = m_SceneMgr->createCamera(m_CamName);
                 SceneNode* camNode =
                    m_SceneMgr->getRootSceneNode()->createChildSceneNode(m_CamSceneNodeName);
                   camNode->attachObject(m_pCamera);
                  m_pCamera->setPosition(0,0,200);
                  m_pCamera->setFarClipDistance(100);
                  m_pCamera->setNearClipDistance(0.51);
                  //m_pCamera->setVisible(true);

                  Viewport *v = rttTex->getBuffer()->getRenderTarget()->addViewport( m_pCamera );
                  v->setOverlaysEnabled(false);
                  v->setClearEveryFrame( true );
                  v->setBackgroundColour( ColourValue::Black );
                  //v->
                  m_pCamera->setAspectRatio(0.4/0.6);
             }
             else
             {
                Viewport *v = rttTex->getBuffer()->getRenderTarget()->addViewport( m_pCamera );
                v->setOverlaysEnabled(false);
                v->setClearEveryFrame( true );
                v->setBackgroundColour( ColourValue::Black );


             }

            }

   // Retrieve CEGUI texture for the RTT
       m_rttTexture = m_GUIRenderer->createTexture((CEGUI::utf8*)m_RttTexName.c_str(), (CEGUI::utf8*)"General");

            CEGUI::Imageset* rttImageSet =
                CEGUI::ImagesetManager::getSingleton().createImageset(
                        (CEGUI::utf8*)m_RttImagesetName.c_str(), m_rttTexture);
   
            rttImageSet->defineImage((CEGUI::utf8*)m_RttImageName.c_str(),
                    CEGUI::Point(0.0f, 0.0f),
                    CEGUI::Size(m_rttTexture->getWidth(), m_rttTexture->getHeight()),
                    CEGUI::Point(0.0f,0.0f));

 
//use it,these line of codes is not in the same function as that above
CEGUI::Imageset* rttImageSet =
      CEGUI::ImagesetManager::getSingleton().getImageset(
      (CEGUI::utf8*)m_RttImagesetName.c_str());

   si->setProperty("Image", CEGUI::PropertyHelper::imageToString(
      &rttImageSet->getImage((CEGUI::utf8*)m_RttImageName.c_str())));
 


Thanks Eddie

singbol
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Sun Aug 23, 2009 04:44

Re: Render To Texture

Postby singbol » Tue Sep 22, 2009 09:24

My 3d scene's environment is black, and only a player stand there, I just want my player placed on the StaticImage, not the black environment, but now the black background is also rendered to the StaticImage, where the black pixel should be the UI's background(StaticImage, too)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Render To Texture

Postby CrazyEddie » Tue Sep 22, 2009 13:03

In order to clear the alpha on the texture, you'll have to specify that explicitly in the clear / background value. For example, instead of:

Code: Select all

v->setBackgroundColour( ColourValue::Black );

do:

Code: Select all

v->setBackgroundColour( ColourValue(0, 0, 0, 0) );


Depending upon where the blackness in your main environment comes from, the above change may be enough to get what you want (if the blackness comes from geometry, it will not be though. For that I guess you'll have to find a means of not drawing that on the RTT pass; I do not know enough about Ogre to advise on that aspect).

HTH

CE.

singbol
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Sun Aug 23, 2009 04:44

Re: Render To Texture

Postby singbol » Tue Sep 22, 2009 13:47

:D Thank you very much!Yeah, it works!aha!

chris
Just popping in
Just popping in
Posts: 1
Joined: Fri Oct 30, 2009 04:16

Re: Render To Texture

Postby chris » Fri Oct 30, 2009 04:38

Hi!
But my question is similar and I have dared to post here.
How can I bind my Direct3D render-target and StaticImage?

Based on this code,

Code: Select all

TexturePtr rttTex = TextureManager::getSingleton().createManual(m_RttTexName,
             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,
             512, 512, 1, 0, PF_R8G8B8A8, TU_RENDERTARGET);
...
m_rttTexture = m_GUIRenderer->createTexture((CEGUI::utf8*)m_RttTexName.c_str(), (CEGUI::utf8*)"General");


I desided that the texture and the render-target have bound by name (RttTexName). But the author used Ogre, I use Direct3D9Renderer.

Thanks in advance.


Return to “Offtopic Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest