RenderToSurface class woes

Started by
3 comments, last by neneboricua19 18 years, 8 months ago
I'm trying to render to a texture, but for some reason, I get D3DERR_INVALIDCALL exceptions. This is my code:

		private void RenderIntoSurface()
		{
			try
			{
        			renderTexture = new Texture(device, RenderSurfaceSize, RenderSurfaceSize, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
                                
				rts = new RenderToSurface(device, RenderSurfaceSize, RenderSurfaceSize, Format.X8R8G8B8, true, DepthFormat.D16);
				renderSurface = renderTexture.GetSurfaceLevel(0);

				Viewport v = new Viewport();
				v.Width = RenderSurfaceSize;
				v.Height = RenderSurfaceSize;
				v.MaxZ = 1.0f;

				rts.BeginScene(renderSurface, v);
				device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0);

				device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 1000.0f);
				device.Transform.View = Matrix.LookAtLH(new Vector3(0,0, -580), new Vector3(), new Vector3(0,1,0));

				DrawMesh(angle / (float)Math.PI, angle / (float)Math.PI * 2.0f, angle / (float)Math.PI / 4.0f, 0, 0, 0);
				DrawMesh(angle / (float)Math.PI, angle / (float)Math.PI / 2.0f, angle / (float)Math.PI * 4.0f, 150, -100, 175);

				rts.EndScene(Filter.None);
			}
			catch (Direct3DXException e)
			{
				System.Console.WriteLine((long)e.ErrorCode + " " + e.ErrorString);
			}
		}

I get the exception on the call to rts.BeginScene(renderSurface, v); And the stack-trace:

   at Microsoft.DirectX.Direct3D.RenderToSurface.BeginSceneInternal(Surface surface, Viewport& viewport)
   at Microsoft.DirectX.Direct3D.RenderToSurface.BeginScene(Surface surface, Viewport viewport)
   at D3D_Chap1.Form1.RenderIntoSurface() in e:\projects\c#\games\managed directx kickstart\chapter 9 - render to surface\form1.cs:line 156

Any ideas why this is wrong? Toolmaker

Advertisement
Is rendertosurface() looped?

If it is you might want to reconsider creating a new texture every frame.
Been away from the comp for 2 days, and I tried it, but it doesn't work. Re-creating the texture EACH frame is a bad idea too, as it sucks up memory.

Any ideas on this? I tried [google], but I can't seem to find an answer.

Toolmaker

bump?

I'm not familiar with Managed DirectX but I'll try to help.

What does the debug spew say? When any DirectX call fails, a text string is printed out to the debug spew so that you know why it failed. If you're not sure what I'm talking about, see the Forum FAQ for information on how to view the debug spew.

Does the problem still happen if you try to render the same scene to the screen instead of to another texture?

neneboricua

This topic is closed to new replies.

Advertisement