Problem With SetRenderTarget

Started by
3 comments, last by surferkid993 12 years, 9 months ago
I'm working in XNA 3.0 and trying to create a refraction map for water. It works great on Windows, but when I run it on my Xbox I am getting a problem. Its a split screen game so player 1 viewport is drawn first, then player 2 is drawn, but for some reason when player 2s screen is drawn it clears player 1 viewport. I am so confused as to why this works on windows and not on Xbox. Here is my code:


refractionRenderTarget = new RenderTarget2D(device, Cam.GetViewport().Width, Cam.GetViewport().Height, 1, device.DisplayMode.Format);

device.SetRenderTarget(0, refractionRenderTarget); //If I comment this out both viewports are drawn...

device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

DrawTerrain(Cam.getViewMatrix(), Cam);
((Game1)base.Game).DrawWorld(PlayerNum);

device.SetRenderTarget(0, null);
device.Viewport = Cam.GetViewport();
refractionMap = refractionRenderTarget.GetTexture();

Advertisement
Bump.
I hope that "refractionRenderTarget" isn't being created every frame.

It's very likely in the PC your render targets are not sharing the depth buffer while in XBox they do, or viceversa. Therefore when you do a Clear the contents of the Z-Buffer are cleared too for both RTs in one case, and separately for the other one. Just a guess.

You didn't mention how you render the two screens. Do you use a scissor rect? two RTs?

Cheers

Dark Sylinc

Thanks for the reply.

Yeah, I know :) I moved refractionRenderTarget to the Draw method one to make sure that it wasn't the problem and two to make my code simpler and readable on here.


That was my first thought too. For whatever reason it was clearing my Z-buffer for both render targets. However I tried not clearing the buffer. However player one's screen still didn't draw...

What I have been doing to draw two screens is using Viewport. Each players camera has a viewport associated with it so that it can be set depending on what screen needs to be drawn. I have been doing a little bit of work with scissor rectangles. It seems they are automatically set when the viewport is changed, I think this is the big part of my problem. I tried just using scissor rectangles and it cuts the screen perfectly on windows however on Xbox it does not even seem to use the scissor rectangle and rather just draws over the whole screen.

So, I think what is happening is, while my viewport is only the bottom half of the screen Xbox doesn't use the scissor rectangle to draw only on that part of the screen. I'm not sure of any of this though. It's mostly assumptions.

But how do i fix it? I set ScissorTestEnable to true is there something else I have to do for Xbox?
Bump. Still having trouble with this.

This topic is closed to new replies.

Advertisement