rendering text to surface problem

hi guys i am trying to write a text on 3d surface so i did the following 
code but i am getting an error in it in the line device.SetRenderTarget(0,surf);
 note that my text is always changing on the surface so it is not possible to write it directly on the texture out side directx ok 
plese help me correcting this code .	
 
		Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono);
			Surface surf = _TArrayButtomBoard.GetSurfaceLevel(0);

//	MyTexture=new Texture(device,200,200,1,Usage.RenderTarget,Format.A8B8G8R8,Pool.Default);
	  	device.SetRenderTarget(0,surf);
			gameFont.DrawText(null, "CameraYPoz = " + CameraYPoz.ToString(), new Rectangle(45,100,0,0), DrawTextFormat.NoClip, Color.WhiteSmoke);
		
			device.SetRenderTarget(0,backbuffer);
		
	  	DrawVB(device , VB , _TArrayButtomBoard , -10 , 32 , 0.0f , -10 , -30.5f ,0,0,0);






Answer this question

rendering text to surface problem

  • AmitK

    I'm a c++ programmer but I can tell you the step you need

    This call get you the surface of the whole screen...that's probably not what you need for your texture surface...it will be for the main render

    Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono);

    I don't know what this do but it's for the main render

    Surface surf = _TArrayButtomBoard.GetSurfaceLevel(0);

    You should create this texture, so you should uncomment this:


    // MyTexture=new Texture(device,200,200,1,Usage.RenderTarget,Format.A8B8G8R8,Pool.Default);

    You need to declare a surface ptr and use your texture to get the surface on your texture, something like this:

    D3DSurface surf2;

    Texture.GetSurface(0,surf2)

    After this you tell the target on the surface that in IN your texture...

    device.SetRenderTarget(0,surf2);

    Before drawing this text you need to call

    device.BeginScene()

    Whatever you render here goes to your texture surface surf2

    gameFont.DrawText(null, "CameraYPoz = " + CameraYPoz.ToString(), new Rectangle(45,100,0,0), DrawTextFormat.NoClip, Color.WhiteSmoke);

    Then you call

    device.EndScene()

    The mistake you should not do is to call this inside the BeginScene and EndScene of your final 3D scene...This Render on Texture must happen before this so not between any other BeginScene and EndScene call of the main render loop

    After you render separatly on your texture you proceed to do the real 3D render totally independently..think of it has preparing texture in advance before your render loop

    I'm not sure if this work, but it can :


    device.SetRenderTarget(0,backbuffer);

    You need to call

    pDevice.BeginScene here

    Set your texture that you prepared and rendered so you can now use it

    pDevice.SetTexture(0,Texture)

    Use it in your scene:


    DrawVB(device , VB , _TArrayButtomBoard , -10 , 32 , 0.0f , -10 , -30.5f ,0,0,0);

    Close your main scene

    pDevice.EndScene();

    Flip the back to the front,

    pDevice.Swap()

    The most common mistake is to put the BeginScene and EndScene of you render to texture inside the BeginScene and EndScene of your main render...

    Hope this can help



  • rendering text to surface problem