Rendering to a array

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
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Rendering to a array

Post by bit-pusher »

Greetings friends.

I'm experienced with C++ and Irrlicht, but I've hit a stumbling block I'm hoping someone can direct me out of.

I want to render a scene with Irrlicht, but I don't want to display it directly; I just want to render the frame into eg a char array.

I don't expect the OpenGL or DirectX renderers will particularly want to do this. However, I only need low resolution - 320 x 240 max (don't even ask what the project is :D) - so I figure all I need do is tweak one of the software renderers to render into an array.

I've been having a look through the source, and I think once I find the right method to amend it should be fairly straight forward, but my eyes are glazing... I could really use a suggestion on the particular method I should look into editing/replacing.

Many thanks for any help you can offer.
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Maybe the "Render to Texture" tutorial on the Irrlicht sourceforge page might help you. I think it just renders to a buffer within a texture.
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post by bit-pusher »

Brainsaw - (name from a Therapy? lyric??) - thanks! I was thinking ITexture didn't support pixel access but I see ITexture::lock() returns a void pointer to the pixel data.

I'll have a play and see if I can get that working.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post by bit-pusher »

Awesome -- works great. Thanks for the pointer Brainsaw, wheel reinvention avoided.

Trivial use case example rendering to a bitmap file:

Code: Select all

    // Create render target
	if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) exit(1);
    video::ITexture* rt = driver->addRenderTargetTexture(core::dimension2d<s32>(256,256), "RTT1");

    driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));

    // Render once, testing
    device->run();
	driver->beginScene(true, true, 0);
	driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));  // Set + clear RTT
	smgr->drawAll();
	driver->endScene();

	// Create image from RTT
	video::IImage* image = driver->createImageFromData (
		rt->getColorFormat(),
		rt->getSize(),
		rt->lock(),
		true
	);
	rt->unlock();

	// Save it
	driver->writeImageToFile(image,"look_it_works.bmp");
	image->drop();
Post Reply