Changing camera affects already drawn objects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ison
Posts: 42
Joined: Sun Mar 24, 2013 9:09 pm

Changing camera affects already drawn objects

Post by ison »

Hello.

I have a problem with rendering the same scene using 2 cameras and 2 render targets (one is texture, one is frame buffer).

My code is as follows:

Code: Select all

void Device::draw()
{
    TRACK;
 
    irr::IrrlichtDevice &irrDevice = getIrrlichtDevice();
 
    irrDevice.getVideoDriver()->beginScene(true, true, irr::video::SColor(255, 0, 0, 255));
    irrDevice.getSceneManager()->setActiveCamera(m_irrSunCamera);
    irrDevice.getVideoDriver()->setRenderTarget(m_sunDepth, true, true);
    irrDevice.getSceneManager()->drawAll();
 
    irrDevice.getVideoDriver()->setRenderTarget(irr::video::ERT_FRAME_BUFFER, true, true);
    irrDevice.getSceneManager()->setActiveCamera(m_irrCamera);
    irrDevice.getSceneManager()->drawAll();
 
    irrDevice.getVideoDriver()->draw2DImage(m_sunDepth, irr::core::rect <irr::s32> (0, 0, 300, 300), irr::core::rect <irr::s32> (0, 0, 1024, 768));
 
    getGUIManager().draw();
 
    irrDevice.getVideoDriver()->endScene();
}
The problem is that when I change active camera using this line (line from code above):

Code: Select all

irrDevice.getSceneManager()->setActiveCamera(m_irrCamera);
Contents of m_sunDepth RTT gets overwritten as if they were rendered using the second camera since beginning. It looks as if drawAll didn't draw anything, but rather queried everything until endScene() is called. Despite I called drawAll with first camera active, it's still drawn as if second camera was active.

If I comment out setting second camera as active. First RTT has correct content (drawn with first camera).

Here are some screenshots:

If I comment setting second camera as active, I get this result:
https://dl.dropboxusercontent.com/u/12301540/misc/1.jpg
Top left RTT is drawn correctly, using firrst camera. But main scene is also rendered using the first camera (because I commented out setting second camera as active).

Now if I uncomment setting second camera as active, I get this:
https://dl.dropboxusercontent.com/u/12301540/misc/2.jpg
Top left RTT got overwritten, despite being drawn BEFORE setting second camera as active.

I've tried changing setActiveCamera/setRenderTarget order, nothing helps.

Is it a bug or a feature?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Changing camera affects already drawn objects

Post by hendu »

If you need to change cameras midway a frame like that, IIRC you need to call the camera's render() after setActiveCamera.
ison
Posts: 42
Joined: Sun Mar 24, 2013 9:09 pm

Re: Changing camera affects already drawn objects

Post by ison »

hendu wrote:If you need to change cameras midway a frame like that, IIRC you need to call the camera's render() after setActiveCamera.
I love you. It worked!
Post Reply