Render to texture problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Render to texture problem

Post 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?
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
latentdisposition
Posts: 29
Joined: Mon Jun 27, 2005 1:17 pm

Post by latentdisposition »

You need to put

Code: Select all

smgr->drawAll();
after

Code: Select all

smgr->setActiveCamera(fixedCam);
"The creation of something new is not accomplished by the intellect but by the play instinct acting from inner necessity. The creative mind plays with the objects it loves."

Carl Jung
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post 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)
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
latentdisposition
Posts: 29
Joined: Mon Jun 27, 2005 1:17 pm

Post 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.
"The creation of something new is not accomplished by the intellect but by the play instinct acting from inner necessity. The creative mind plays with the objects it loves."

Carl Jung
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post 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.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Post Reply