When i try to do a render to texture 50% of the time it will work fine however the other 50% of the time i get a random section of my main scene.
The code is pretty much the same as the example.
I am using a texture size of 256 by 256.
On the times when it doesn't work, when i try to draw the texture i get a small portion of the screen drawn on the texture. It even updates as the program is running and shows the changes to the scene. This happens even when i am not updating the texture. if i try to update the texture it makes no difference.
Does any one know how to fix this?
I am running in Linux using the OpenGL driver.
thanks
RTT question
the code im using is
the only other difference is that i changed COpenGLTexture.cpp in the source so that the FBO object used GL_RGBA instead of GL_RGB8. as this allows for alpha channels in render to texture
Code: Select all
#include <irrlicht.h>
#include <COpenGLTexture.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
IrrlichtDevice *device =createDevice(video::EDT_OPENGL, dimension2d<s32>(0,0), dimension2d<s32>(640, 480), 32, false, false, false, 0);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ISceneNode* testscene = smgr->addCubeSceneNode(60);
// let the cube rotate
scene::ISceneNodeAnimator* animtest = smgr->createRotationAnimator(
core::vector3df(0.3f, 0.7f,0.2f));
testscene->getMaterial(0).MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
testscene->setPosition(core::vector3df(0,0,0));
testscene->setMaterialTexture(0,
driver->getTexture("/home/projects/prototypes/texturerender/test3.tga")); // set diffuse texture
testscene->setMaterialFlag(video::EMF_LIGHTING, false); // enable dynamic lighting
testscene->addAnimator(animtest);
animtest->drop();
// add fps camera
scene::ICameraSceneNode* fpsCamera = smgr->addCameraSceneNodeFPS();
fpsCamera->setPosition(core::vector3df(0,0,-100));
// create test cube
scene::ISceneNode* test = smgr->addCubeSceneNode(80);
// let the cube rotate and set some light settings
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(
core::vector3df(0.3f, 0.3f,0));
test->setPosition(core::vector3df(0,0,0));
test->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
test->getMaterial(0).MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
test->addAnimator(anim);
anim->drop();
scene::ISceneNode* secondtest = smgr->addCubeSceneNode(60);
// let the cube rotate and set some light settings
scene::ISceneNodeAnimator* secondanim = smgr->createRotationAnimator(
core::vector3df(0.6f, 0.6f,0.3f));
secondtest->setPosition(core::vector3df(0,0,0));
secondtest->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
secondtest->getMaterial(0).MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
secondtest->addAnimator(secondanim);
secondanim->drop();
// set window caption
device->setWindowCaption(
L"Irrlicht Engine - Render to Texture");
// create render target
video::COpenGLTexture* rt = 0;
scene::ICameraSceneNode* fixedCam = 0;
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
rt = (COpenGLTexture*) driver->createRenderTargetTexture(core::dimension2d<s32>(256,256));
test->setMaterialTexture(0, rt); // set material of cube to render target
secondtest->setMaterialTexture(0, rt); // set material of cube to render target
// add fixed camera
fixedCam = smgr->addCameraSceneNode(0, core::vector3df(0,0,-100),
core::vector3df(0,0,0));
}
else
{
printf("fucked\n");
return 1;
}
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
if (rt)
{
// draw scene into render target
// set render target texture
driver->setRenderTarget(rt, true, true, video::SColor(0,255,0,0));
// make cube invisible and set fixed camera as active camera
testscene->setVisible(true);
test->setVisible(false);
secondtest->setVisible(false);
smgr->setActiveCamera(fixedCam);
// draw whole scene into render buffer
smgr->drawAll();
// set back old render target
driver->setRenderTarget(0, true, true, video::SColor(0,255,255,255));
// make the cube visible and set the user controlled camera as active one
test->setVisible(true);
secondtest->setVisible(true);
testscene->setVisible(false);
smgr->setActiveCamera(fpsCamera);
}
else
{
printf("rt is fucked\n");
}
// draw scene normally
smgr->drawAll();
driver->endScene();
}
if (rt)
rt->drop(); // drop render target because we
// created if with a create() method
device->drop(); // drop device
return 0;
}the only other difference is that i changed COpenGLTexture.cpp in the source so that the FBO object used GL_RGBA instead of GL_RGB8. as this allows for alpha channels in render to texture