Sign in to follow this  
Annoyed

Problems with MDX Texture.GetSurfaceLevel

Recommended Posts

My miniature app is meant to draw text on a texture object surface and then render it to screen via a square of TransformedColoredTextured vertices. It works brilliant in windowed mode but in full screen something goes wrong and I have no idea why. The initialize device is taken out of the average online tutorial, nothing fancy going on. The render call looks like this:
protected override void OnPaint( PaintEventArgs e )
{
    this.device.Clear( ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0 );

    this.device.BeginScene();
    this.device.RenderState.Lighting = false;
    this.device.RenderState.CullMode = Cull.None;
    this.device.RenderState.FillMode = FillMode.Solid;
    this.device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;

    this.device.RenderState.AlphaBlendEnable = true;
    this.device.RenderState.AlphaFunction = Compare.Always;
    this.device.RenderState.SourceBlend = Blend.SourceAlpha;
    this.device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
    this.device.RenderState.AlphaBlendOperation = BlendOperation.Min;

    if ( this.isDirty )
    {
        // Store current render target.
        Surface renderTarget = device.GetRenderTarget( 0 );

        //Surface newFace = this.texture.GetSurfaceLevel( 0 );

        // Set text texture as render target.
        this.device.SetRenderTarget( 0, this.texture.GetSurfaceLevel( 0 ) );

        // Clear target as transparent.
        this.device.Clear( ClearFlags.Target, Color.Transparent, 1.0f, 0 );

        // Draw some text,
        this.sprite.Begin( SpriteFlags.AlphaBlend | SpriteFlags.SortTexture );
        this.dxFont.DrawText( this.sprite, this.text, new Point( 5, 5 ), Color.Green.ToArgb() );
        this.sprite.End();

        // Reset render target.
        this.device.SetRenderTarget( 0, renderTarget );

        this.isDirty = false;
    }

    this.device.SetTexture( 0, this.texture );

    this.device.SetStreamSource( 0, this.vertexBuffer, 0, CustomVertex.TransformedColoredTextured.StrideSize );
    this.device.DrawPrimitives( PrimitiveType.TriangleList, 0, 2 );

    this.device.EndScene();
    this.device.Present();

    this.Invalidate();
}

This isDirty variable is set to true everytime the text variable has been altered. That is when the texture is supposed to be redrawn but it is also then the error occurs. I have narrowed it down to that it is the following call that fails:
this.texture.GetSurfaceLevel( 0 )

I cannot find an explanation as to why this happens. But the confusion is capped by the fact that it works in windowed mode. Can someone give me a hint on what is going on and what I may have overlooked?

Share this post


Link to post
Share on other sites
Object reference not set to a instance of an object.

If I store the Surface refernce globally after creating the texture it works fine.

However when i use the device.SetRenderTarget(0, surfaceReference);

I get the Error in the application memory corrupt message.

And as I said this happens only in full screen mode =/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this