XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Restoring depthstate after using my pFont object

Last post 08-30-2008 10:12 AM by Ralf Kornmann. 1 replies.
  • 08-24-2008 9:24 AM

    Restoring depthstate after using my pFont object

    I'm having trouble with my depthstate. I want to render text and a terrain but I cant seem to restore the depthstate after written some text.

     Whats wrong: my app should shown me a terrain with text but I only get the text. If i remove the DrawFont the terrain appears prefectly.

     My DrawFont func:

    void DrawFont()
    {
        // Create and Initialize the destination rectangle
        RECT rc;
        SetRectEmpty(&rc);
        rc.top = 100;
        rc.left = 100;

        // Use the GetFontRectangle helper function to get the proper size
        // of the rectangle.
        GetFontRectangle(TEXT("This is a test string"), &rc);

        
        pFontSprite->Begin(D3DX10_SPRITE_SORT_TEXTURE | D3DX10_SPRITE_SAVE_STATE );

        // Draw the text to the screen
        HRESULT hr = pFont->DrawText(
            pFontSprite,
            TEXT("This is a test string"),
            -1,
            &rc,
            DT_LEFT,
            D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f) );

        // Save the current blend state
        pD3DDevice->OMGetBlendState(&pOriginalBlendState10, OriginalBlendFactor, &OriginalSampleMask);

        // Set the blend state for font drawing
        if(pFontBlendState10)
        {
            FLOAT NewBlendFactor[4] = {0,0,0,0};
            pD3DDevice->OMSetBlendState(pFontBlendState10, NewBlendFactor, 0xffffffff);
        }

        pFontSprite->End();

        // Restore the previous blend state
        pD3DDevice->OMSetBlendState(pOriginalBlendState10, OriginalBlendFactor, OriginalSampleMask);
    }

     Notice that I use pFontSprite->Begin(D3DX10_SPRITE_SORT_TEXTURE | D3DX10_SPRITE_SAVE_STATE );, and I though it would save my state then later on restore on pFontSprite->End();... but I'm wrong and all i get is text in my little app.

     

  • 08-30-2008 10:12 AM In reply to

    Re: Restoring depthstate after using my pFont object

    Following your code you try to save and restore the blend state but not the depth stencil state. Additional you save the state after you have called Begin and write it back after End. This way you “restore” the state that the font object is using to render the text.

Page 1 of 1 (2 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG