RTT question

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
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

RTT question

Post by daveslip »

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
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Maybe you should post some code and screenshots ?
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

Post by daveslip »

having modified stuff a little i now get a plain white texture instead of the area of the screen.

as i set the clear colour to black there is definatly something going a miss.

as far as code goes its simply the same as the RTT tutorial.

i have removed everything else from the program now

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

Post by hybrid »

Well, the RTT tutorial works under Linux with OpenGL. So how can we help then?
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

Post by daveslip »

yeah the tutorial works but not every time i run it

wanted to know if anyone else had a problem with a white/blank texture that didnt seem to get updated when rendered to
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, I have several linux systems with different gfx cards. And all can run the tutorial without problems. It might be your driver, try to update to a more recent version. Which card/driver do you use?
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

Post by daveslip »

the card is a nVidia geforce go 6100 and the driver is version 9746
Last edited by daveslip on Fri Jun 22, 2007 9:19 am, edited 1 time in total.
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

Post by daveslip »

the code im using is

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

Post by hybrid »

Don't use ALPHA_CHANNEL with RTT.
daveslip
Posts: 7
Joined: Thu Jun 21, 2007 9:38 am

Post by daveslip »

why not?

is there an alternative?

also this happened before i changed the RGBA stuff

as originally i was calculating the alpha channel by doing two renders against different backgrounds and using a spot the difference type thing
Post Reply