Jump to content
  • Advertisement
Sign in to follow this  

Problems with MDX Texture.GetSurfaceLevel

This topic is 3888 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

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.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() );

        // 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 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
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!