Ways of splitscreen with water scene node [SOLVED]

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!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

What did you achieve so far, what happened when you tried the things you found out so far? There's no way for us to help is you don't tell.
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

nothing happened
I called

OnAnimate(timer);
OnRegisterSceneNode();
render();

AND I sTIll CANNOT SEE IT!!!
It only renders if i make it the child of RootSceneNode!!!!!!!!!

So I am wondering... looking at the third example of the tutorial, i see that the custom tetrahedron scene node is not the child of RootSceneNode and its render() function is not empty (unlike Water scene node) but it has DrawVertices(). So I ask What should I put in the render function for the Water scene node to render????

drawMeshbuffer() maybe???
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

OK I FOUND THIS

driver->setMaterial(Material);
core::matrix4 Mat;
Mat.makeIdentity();

//On sauvegarde les matrices
core::matrix4 MatrixWorld = driver->getTransform(video::ETS_WORLD);
core::matrix4 MatrixView = driver->getTransform(video::ETS_VIEW);

//On applique les matrices de monde et de vue
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setTransform(video::ETS_VIEW,Mat);
//On dessine nos Quad ici
//The mesh of the water is static
WaterMesh()->getMeshBuffer()->setHardwareMappingHint(EHM_STATIC);
driver->drawMeshBuffer(WaterMesh()->getMeshBuffer());

//On restaure les matrices
driver->setTransform(video::ETS_VIEW,MatrixView);
driver->setTransform(video::ETS_WORLD,MatrixWorld);
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, BlindSide already told you to set up the transformation matrices etc. It's probably time to do so.
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

oh yeah i finnaly was able to do it!!

Code: Select all

void RealisticWaterSceneNode::render() {
   VideoDriver->setMaterial(WaterSceneNode->getMaterial(0));
   irr::core::matrix4 Mat;
   Mat.makeIdentity();

   //On sauvegarde les matrices
   irr::core::matrix4 MatrixWorld = VideoDriver->getTransform(irr::video::ETS_WORLD);
   irr::core::matrix4 MatrixView = VideoDriver->getTransform(irr::video::ETS_VIEW);

   //On applique les matrices de monde et de vue
   VideoDriver->setTransform(irr::video::ETS_WORLD, AbsoluteTransformation);
   VideoDriver->setTransform(irr::video::ETS_VIEW,Mat);
   //On dessine nos Quad ici
   //The mesh of the water is static
   WaterMesh->getMeshBuffer(0)->setHardwareMappingHint(irr::scene::EHM_STATIC);
   VideoDriver->drawMeshBuffer(WaterMesh->getMeshBuffer(0));

   //On restaure les matrices
   VideoDriver->setTransform(irr::video::ETS_VIEW,MatrixView);
   VideoDriver->setTransform(irr::video::ETS_WORLD,MatrixWorld);

}
BUT IT STILL DOESNT WANT TO RENDER INTO VIEWPORTS!!!
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

hehe funny, I commented out //Water->OnAnimate(ITimer*);
and split screen works!!

I think its the fault of RTT and ViewPorts.
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

Render Targets screw up the view ports :(

what do now?
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

Honestly I tried everything I EVEN made a workaround using two textures (as to p and bottom of the screen) and setting the render targets to them after OnAnimate(), drawing the scene and then drawing the textures with driver->draw2DImage(TopScreen (or bottom whichever applicable, position2di())
and it still doesnt work.
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

i kind of have it half working, the top screen renders fine but the bottom stays blank. Because i have that little thing that checks if you are under or above the water (it makes the game not call OnAnimate), if you go under then you can see both screens fine.
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

WEll i have almost reached my goal, I have made two begin scenes and end scenes, in the first the first camera is rendered and in the second the other camera renders. The water works, but the screen flickkerrs like hell.

Anysolution to that??
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The problem is probably that you didn't understand what happens at those beginScene and endScene calls. However, there's no way to really help you without seeing code (better yet to strip it down to only a few RTT calls instead of having to deal with all water shaders and stuff!).
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

oh its allright now i told it not to clear the back buffer when doing a new scene and when switching RTT to 0.

Code: Select all

void SplitScreenLoop(irr::scene::ICameraSceneNode* cam1,irr::scene::ICameraSceneNode* cam2, RealisticWaterSceneNode* Water) {
   int lastFPS = -1;
   int fps;
   irr::video::IVideoDriver* driver = device->getSceneManager()->getVideoDriver();
   irr::scene::ISceneManager* smgr = device->getSceneManager();
   while (device->run()) {
      if (device->isWindowActive()) {
         driver->beginScene(false, true);
         driver->setViewPort(irr::core::rect<irr::s32>(0,(res.y/2),res.x,res.y));
         smgr->setActiveCamera(cam2);
         if (cam2->getPosition().Y>=Water->getAbsolutePosition().Y) {
            Water->OnAnimate(device->getTimer()->getTime(),2);
            driver->setViewPort(irr::core::rect<irr::s32>(0,(res.y/2),res.x,res.y));
            Water->OnRegisterSceneNode();
            Water->render();
            driver->setViewPort(irr::core::rect<irr::s32>(0,(res.y/2),res.x,res.y));
         }
         smgr->drawAll();
         driver->endScene();
         driver->beginScene(false, true, irr::video::SColor(0,0,0,0));
         driver->setViewPort(irr::core::rect<irr::s32>(0,0,res.x,(res.y/2)));
         smgr->setActiveCamera(cam1);
         if (cam1->getPosition().Y>=Water->getAbsolutePosition().Y) {
            Water->OnAnimate(device->getTimer()->getTime(),1);
            driver->setViewPort(irr::core::rect<irr::s32>(0,0,res.x,(res.y/2)));
            Water->OnRegisterSceneNode();
            Water->render();
            driver->setViewPort(irr::core::rect<irr::s32>(0,0,res.x,(res.y/2)));
         }
         smgr->drawAll();
         driver->endScene();
         //driver->clearBackBuffer(); This is the type of thing i'm looking for
         fps = driver->getFPS();
         if (lastFPS != fps) {

            irr::core::stringw str = L"Project Ninja Star - Nexuiz Map example FPS:";

            str += fps;

            device->setWindowCaption(str.c_str());

            lastFPS = fps;

         }
      }
      else
         device->yield();
   }
}
but now i need a method to clear the back buffer on the ned of my loop!!

is there any function like driver->clearbackbuffer();??? (i cant find one in API)
Last edited by devsh on Sun Feb 22, 2009 6:08 pm, edited 3 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Shouldn't the end of your render loop be the beginning of the next?
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

If that is what you are after

No, putting true to clear backbuffer in the first beginscene does not work.
Post Reply