Hi, I am trying to do the same thing, this is how far I've gotten:
I am trying to render an Ogre scene into a texture target and draw this in a CEGUI component. This works fine.
What I am now trying to do is make the render-texture larger than the CEGUI component it is being drawn into, to get AA.
What I do is as follows:
Code: Select all
if(!mWrappedStaticImage->isUsingAutoRenderingSurface())
mWrappedStaticImage->setUsingAutoRenderingSurface(true);
CEGUI::RenderingSurface *const surface = mWrappedStaticImage->getRenderingSurface();
if(surface == NULL)
{
LOG_MSG(String("Attempting to render ") + sceneManagerName + String(" to StaticImage, but it does not have a RenderSurface"), IO::Log::LEVEL_ERRORS, "Gui");
return;
}
CEGUI::OgreTextureTarget& ceguiTextureTarget = dynamic_cast<CEGUI::OgreTextureTarget&>(surface->getRenderTarget());
CEGUI::Size orgTexSize = ceguiTextureTarget.getTexture().getSize();
// Double the size of the render-target to get AA
ceguiTextureTarget.declareRenderSize(CEGUI::Size(orgTexSize.d_width * SFloat(2), orgTexSize.d_height * SFloat(2)));
Ogre::RenderTexture *const ogreRenderTexture = dynamic_cast<CEGUI::OgreTexture&>(ceguiTextureTarget.getTexture()).getOgreTexture()->getBuffer()->getRenderTarget();
if(!sceneMan->hasCamera(cameraName))
{
LOG_MSG(String("Attempting to use Camera ") + cameraName + String("for OgreScene in StaticImage, but it does not exist!"), IO::Log::LEVEL_ERRORS, "Gui");
return;
}
Ogre::Camera *const camera = sceneMan->getCamera(cameraName);
//Add a Viewport to the render texture with our camera.
Ogre::Viewport *const vp = ogreRenderTexture->addViewport(camera);
vp->setOverlaysEnabled(false);
vp->setBackgroundColour(Ogre::ColourValue(SFloat(0), SFloat(0), SFloat(0), SFloat(0)));
vp->setClearEveryFrame(true);
The problem: The static-image draws the image as though it is 'left and top aligned' instead of 'stretched'.
Calling the 'declareRenderSize' function sets both the 'd_size' and the 'd_dataSize' to be the same value, so when it computes the texel-scaling in CEGUI::OgreTexture, it computes a scaling value assuming that the CEGUI::Window that is drawing this texture IS the same size as the texture. Manually changing d_texelScaling via debugger in CEGUI::OgreTexture achieves the effect I am looking for (i.e. I have to double the d_texelScaling, since I doubled the texture size, giving me the AA effect I am looking for). I think what I need is some way to set 'd_dataSize', or have CEGUI set 'd_dataSize' in CEGUI::OgreTexture to the correct value (in my case, 1/2 of d_size). Is there a way to do this?
What I have done, is modified CEGUI::OgreTexture, I have added 'adjustCachedTexelScaling(float factor) { d_texelScaling = d_texelScaling * factor; }' function. This is a hack, and I am looking for the 'correct' way of doing this.
However, my final, functional code:
Code: Select all
if(!mWrappedStaticImage->isUsingAutoRenderingSurface())
mWrappedStaticImage->setUsingAutoRenderingSurface(true);
CEGUI::RenderingSurface *const surface = mWrappedStaticImage->getRenderingSurface();
if(surface == NULL)
{
LOG_MSG(String("Attempting to render ") + sceneManagerName + String(" to StaticImage, but it does not have a RenderSurface"), IO::Log::LEVEL_ERRORS, "Gui");
return;
}
CEGUI::OgreTextureTarget& ceguiTextureTarget = dynamic_cast<CEGUI::OgreTextureTarget&>(surface->getRenderTarget());
CEGUI::Size orgTexSize = ceguiTextureTarget.getTexture().getSize();
// Double the size of the render-target to get AA
ceguiTextureTarget.declareRenderSize(CEGUI::Size(orgTexSize.d_width * SFloat(2), orgTexSize.d_height * SFloat(2)));
CEGUI::OgreTexture& tex = dynamic_cast<CEGUI::OgreTexture&>(ceguiTextureTarget.getTexture());
tex.adjustCachedTexelScaling(SFloat(2));
Ogre::RenderTexture *const ogreRenderTexture = tex.getOgreTexture()->getBuffer()->getRenderTarget();
if(!sceneMan->hasCamera(cameraName))
{
LOG_MSG(String("Attempting to use Camera ") + cameraName + String("for OgreScene in StaticImage, but it does not exist!"), IO::Log::LEVEL_ERRORS, "Gui");
return;
}
Ogre::Camera *const camera = sceneMan->getCamera(cameraName);
//Add a Viewport to the render texture with our camera.
Ogre::Viewport *const vp = ogreRenderTexture->addViewport(camera);
vp->setOverlaysEnabled(false);
vp->setBackgroundColour(Ogre::ColourValue(SFloat(0), SFloat(0), SFloat(0), SFloat(0)));
vp->setClearEveryFrame(true);
Christian