Page 1 of 1

Render to texture problem

Posted: Fri Oct 14, 2005 1:24 am
by MikeR
http://g2.3dcentral.net/main.php?g2_vie ... itemId=158 <-That's a screenshot of my problem.
I have added a UV mapped screen to my world (dmf file) and set the camera in front of the stage. (I used my avatar to set the camera postion)
The relevant code is below:

Code: Select all

[b]int main[/b]
//Screen mesh
     scene::IAnimatedMeshSceneNode* test = smgr->addAnimatedMeshSceneNode(
		smgr->getMesh("media/vidscreen.dmf"));
     test->setPosition(core::vector3df(550,-1475,1650));
   	test->setMaterialFlag(video::EMF_LIGHTING, false); // enable dynamic lighting 
	test->getMaterial(0).Shininess = 20.0f; // set size of specular highlights

 // add white light-in theater
	scene::ILightSceneNode* light1 = smgr->addLightSceneNode(0,
		core::vector3df(550,-1575,950), video::SColorf(1.0f, 1.0f, 1.0f));
//==========My Video Screen=======render to texture===========
	
    // create render target
	video::ITexture* rt = 0;
	scene::ICameraSceneNode* fixedCam = 0;
	
//Screen texture
	if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
	{
        rt = driver->createRenderTargetTexture(core::dimension2d<s32>(840,840));
		test->setMaterialTexture(0, driver->getTexture("media/screen.jpg"));
		test->setMaterialTexture(0, rt); // set material of cube to render target 
test->getMaterial(0).Shininess = 20.0f; // set size of specular highlights

		// add fixed camera
		fixedCam= smgr->addCameraSceneNode(0, core::vector3df(550,-1795,1250),
			core::vector3df(0,0,0)); 
	
	}
if (rt)
		{
			// draw scene into render target
			
			// set render target texture
			driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));     

			// make cube invisible and set fixed camera as active camera
			test->setVisible(false);
			smgr->setActiveCamera(fixedCam);
			// set back old render target
			driver->setRenderTarget(0);      

			// make the cube visible and set the user controlled camera as active one
			test->setVisible(true);
			smgr->setActiveCamera(camera);
        } 


		smgr->drawAll();
	
I can't for the life of me figure out why this isn't working.
My eyes hurt from staring at code. Anyone see a problem I don't?

Posted: Fri Oct 14, 2005 3:12 am
by latentdisposition
You need to put

Code: Select all

smgr->drawAll();
after

Code: Select all

smgr->setActiveCamera(fixedCam);

Posted: Sat Oct 15, 2005 4:57 pm
by MikeR
Ok, that works.
I have no idea why tho, and it totally messes up my gravity.
With smgr->drawAll(); at the end of the code, everything eccept RTT works properly. My Player camera is glued to the floor. (just how I want it), but when I add smgr->drawAll(); where you suggest, (and where it is in the example.. :oops: ) My player can fly.
Why would I need smgr->drawAll(); twice?
And how can I stop it from messing with my gravity? (I'm using Irrlichts physics)

Posted: Sun Oct 16, 2005 12:20 am
by latentdisposition
You must draw the scene twice for render to texture. Once from your usual camera, and then once from the fixed camera into the target texture. As far as the gravity is concerned I have no idea. Perhaps it is a bug.

Posted: Sun Oct 16, 2005 2:24 pm
by MikeR
Thankyou. Actually, I have fixed the gravity. That was my goof. I removed something (inadvertantly of course) that was needed. Everything is working perfectly now. :) thanks.