Render To Texture Issues

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
SoulRift
Posts: 4
Joined: Sat Jun 18, 2005 11:39 pm

Render To Texture Issues

Post by SoulRift »

Hey, I had a post on the Beginner's Forum with a similar question but I figured what I learned from my own research tends to go beyond a beginner's problem. Here is what I am trying to do:
I would like to create a reflective surface using the RTT feature, and have gotten fairly good results thus far, but when I look at the mirror surface, the image is flopped across the Y axis (not correctly making a mirror image). I figured that there are two ways to fix the problem, either just manually flop the texture at the pixel level (via .lock()) or modify the projection matrix of the camera so that the coordinates are flopped across the Y-axis. Since I'm horrid at vector/matrix math I opted for the prior solution.
I got a subroutine written that would take a texture and swap the pixels. It worked great on textures that I manually loaded, but when it came to the RTT texture, I would get all of the information off of the texture (dimensions, format, etc) but whenever I tried to .lock() the texture I would get a NULL pointer for the array of pixels. I'm assuming its specific to modifying the RTT texture rather than other manually loaded textures. So this brings me to my first question:
Does anyone know why I get a null pointer upon lock()-ing the texture rendered by RTT? Is there some specific reason that it wont allow me to modify it?
Here is he code on how I obtain the pointer to the RTT texture so its less ambiguous:

Code: Select all

	//Checking to see if hardware supports RTT is omitted to make it more brief.
	video::ITexture* rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256));
	sphere->setMaterialTexture(0, rt); // set material of sphere to render target


	// Skipped even more code to go down to the rendering routine:
	if(rt){
		... render the camera's output to the texture and reset our old camera...
	}

	// Flip our texture so that we actually get a mirrored image instead of
	// a really akward looking one off of the ball.
	pixelXSwap(rt);
That last pixelXSwap call with rt as the only argument is the call to my (fairly poorly named) subroutine that swaps the pixels across the Y axis. For some reason when I call that subroutine with that texture, I get all of the information I need from it, except the pixels!

As you can see, I need to swap these pixels every time I render the new RTT texture. I really really dont want to have do this whenever I render the scene; its obviously going to be taxing on the system and slow everything down significantly. Which leads onto my second question:
Is there a way to create a mirror image by modifying one of the matricies in the camera before I render the scene? Its been a very long time since I've gone through the matrix math of how a camera renders 3D images to a 2d texture, but I would think that by somehow modifying the projection matrix (I'm hoping its just the projection matrix since its the only one I know I can modify in irrlicht's cameras) I can create the desired effect.
Any help is much appreciated.
SoulRift
Posts: 4
Joined: Sat Jun 18, 2005 11:39 pm

Post by SoulRift »

Well, after a day of fiddling around with it and finding out that the easiest way to do what I wanted to do what impossible without heavily modifying the irrlicht source, I came up with a hack (which runs fairly quickly) that doesnt look half bad. Still need to tweak a few things but it works.. for now.


Image

Image
Post Reply