Page 1 of 1

[SOLVED] Problem with render to texture with Irrlicht.NET CP

Posted: Wed Jun 18, 2008 8:05 pm
by impulse3d
I've tried searching Google and the forums, but haven't found anything.

I'm trying to render to texture and then display that texture using draw2DImage. However, I'm having some odd problems that look like drawing order problems when I render to a texture--and only when I render to a texture.

Here's an example output image:
Image

That's what happens when I do:

Code: Select all

// _renderTarget is set up using CreateRenderTargetTexture earlier.
_device.VideoDriver.SetRenderTarget(_renderTarget, true, true, Color.Black);
            
_device.SceneManager.DrawAll();

_device.VideoDriver.SetRenderTarget(null, true, true, Color.Black);

// A little bit later...

Rect srcDest = new Rect(0, 0, _device.VideoDriver.ScreenSize.Width, _device.VideoDriver.ScreenSize.Height);
_device.VideoDriver.Draw2DImage(_renderTarget, srcDest, srcDest, Color.White, false);
I see a wall there, like you're supposed to, when just drawing straight to the framebuffer. I know that setting the render target back to the framebuffer works because I can see the default color if I don't make the Draw2DImage call.

I'm guessing that it has something to do with the way z-buffers for the render target are set up vs. the actual framebuffer, but I really have no idea (or no idea where to start looking). I've even followed the render-to-texture tutorial as it says.

Anyone know what's going on? Any help would be superbly appreciated.

Posted: Wed Jun 18, 2008 8:44 pm
by impulse3d
I've actually tried doing the same thing that I'm doing in the C++ render to texture example tutorial (i.e. swapping out their meshes for mine) and it works fine in C++, so maybe it's a problem with the C# wrapper Irrlicht.NET?

Posted: Thu Jun 19, 2008 3:55 am
by BlindSide
Are you using any transparent materials? I had this exact same problem because I used a transparent material on a large mesh, and they happen to have ZWriteEnable disabled by default. That wouldn't explain why it only happens when using an RTT though, I've seen this happen if shaders fail to compile, are you using any shader in conjunction with the RTT?

Posted: Thu Jun 19, 2008 12:40 pm
by impulse3d
Thanks for the reply BlindSide.

I'm not using any transparent materials, and I'm not using any shaders anywhere in this scene (I will eventually, but first I'm just trying to get RTT then straight-up displaying it to the screen to work first). And yes, you're right---I've seen that same exact problem happen when using transparent materials. However, I've tried explicitly setting its ZWriteEnable flag to true, and that doesn't change anything.

So yeah, it's odd that
1. It works fine when I convert the relevant code to C++ and load it up in the tutorial project, and
2. It only happens when rendering to a texture, not when rendering to the framebuffer.

Let me know if you have any other insights as to what the problem may be. Thanks! :D

UPDATE: I've tried loading other meshes like the Quake map from tutorial 2 and that has the same problem. It looks like maybe the render target that I'm creating doesn't have a ZBuffer? Or at least isn't able to write to one?

UPDATE 2: I'm beginning to think that there's an error in the Irrlicht.NET CP bindings that's screwing with something somewhere, since I've done yet another test where I added a method that does a render-to-texture and display in Irrlicht's C++ and called that in both the demo and my C# code and only the demo works. I'm now looking into a bunch of places where the bindings could be going wrong.

Posted: Thu Jun 19, 2008 8:39 pm
by impulse3d
Wow! So I have no idea where the problem was, but I tracked it down to initialization of the IrrlichtDevice:

Device = new IrrlichtDevice(DriverType.Direct3D9, new Dimension2D(1024, 768), 32, false, false, false, true);

I simply changed the last bool to "false", which is the one that controls anti-aliasing. And weird enough, now it works!

It's very odd indeed. :o