Jump to content
  • Advertisement
Sign in to follow this  
Toolmaker

RenderToSurface class woes

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Is rendertosurface() looped?

If it is you might want to reconsider creating a new texture every frame.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!