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);
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.