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

DirectX 10 2D text issue

Last post 11/11/2009 10:11 PM by InsaneMalkavian. 7 replies.
  • 9/1/2007 11:43 AM

    DirectX 10 2D text issue

    Hey,

    I'm new to Direct X 10, in fact to 3D programming in general (this is probably the most common introduction to a problem) and I'm having a problem trying to get text and 3D polygons to render at the same time. I'd prefer not to call the DXUT libray provided with the SDK. I've had a look inside and I'm not quite sure what I'm doing wrong. The text renders fine but no polygons show up.

    When setting up the device:

    D3DX10CreateFont( mDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &mFont );

    D3DX10CreateSprite(mDevice,512,&mFontSprite);

     

     

    When rendering:

     

    mFontSprite->Begin( D3DX10_SPRITE_SORT_TEXTURE );

    RECT rc;
    rc.left=20;
    rc.right=100;
    rc.top=20;
    rc.bottom=100;
    mFont->DrawText(mFontSprite,"Hello World",11,&rc,DT_NOCLIP,D3DXCOLOR(0.0,1.0f,0.0,1.0));

    mFontSprite->End();

    When looking at DXUT I noticed they create a ID3D10BlendState on setup and then before calling End() on the sprite they set the font Blendstate via OMSetBlendState. Then after calling the End() they set the original Blendstate. Tried that and it didn't work.

    Is there something else I need to do in order for the text and polygons to get render together? Is there anything I need to add to the shader file (e.g SetBlendState) ?

     

     

  • 9/2/2007 8:14 AM In reply to

    Re: DirectX 10 2D text issue

    Are your polygons shows when you don’t render the text at all?

  • 9/2/2007 8:35 AM In reply to

    Re: DirectX 10 2D text issue

    Yeah, they came up fine.

    I took my code I'm using to render the text and put it into Tutorial 10: Advanced DXUT. So it would render the text without using CDXUTTextHelper. It worked fine. My text and the polygons would render together. I then moved the code to Tutorial 04: 3D Spaces and I got the same issue I've been having (can't render text with the polygons). This makes me believe that the DXUT is doing something extra in Tutorial 10: Advanced DXUT that I've left out.

    I'm still doing some reading up on ID3D10BlendState and ID3D10DepthStencilView as I'm still hazy on those concepts and I need to determine if they are applicable to my problem.

    Thanks for the reply;)

    PS. Just some background information...I'm using Microsoft DirectX SDK (February 2007) and I'm generating the polygons on the Geometry Shader (I doubt this would cause the issue as I get the same issue when trying to add text to Tutorial 04: 3D Spaces)

     

  • 9/2/2007 8:46 AM In reply to

    Re: DirectX 10 2D text issue

    There are some changes in the D3D10X components since the February SDK.  You should try to update to the August SDK.

    As the Direct3D 10 effect framework don’t restore the state objects you should make sure that your effect file (.FX) set all three state objects (rasterizer, depthstencil and blend) for your polygon pass. If you don’t do this you cannot be sure about the states that are set during your pass.

    Additional you can use PIX to check if the device pipeline ist setup in the way you want it during your polygon pass.

  • 10/9/2007 2:32 PM In reply to

    Re: DirectX 10 2D text issue

    Hello there ive had the same sort of problem. What it is, is the d3dxfont uses its own shader.

    what you need to do is to set vertex buffers and AI buffers before drawing the polygons in the render procedure.

    what the tutorials do (Which i think is very bad for a turorial) is set up the index buffers, AI buffers and so on, in the initdevice procedure and then in render only call the functions to draw. So you need to do something like this :

        UINT stride = sizeof( SimpleVertex );
        UINT offset = 0;

        RG_Direct3dDevice->IASetInputLayout( g_pVertexLayout );

        RG_Direct3dDevice->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );   

        RG_Direct3dDevice->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0 );

        RG_Direct3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

       Then draw your polygons after setting the IAs and set your text rects after this.

    If you are still haveing issues or dont understand what ive typed in ill try and explain it again in more detail

  • 6/22/2008 1:58 AM In reply to

    Re: DirectX 10 2D text issue

    Hello!

    I'm not sure if anyone's still watching this post, but I'm having this problem when I'm just drawing sprites.  If I try to draw text and sprites at the same time, only the text appears--even if I use completely different ID3DX10Sprite objects for them.  So, I don't have vertex buffers or index buffers to reset after D3DX10Font apparently screws them up.  Is there something else I should be resetting after drawing text, given that I haven't explicitly created vertex or index buffers?

  • 8/28/2009 11:59 AM In reply to

    Re: DirectX 10 2D text issue

    Thanks, 2 years on and this was still helpfull.  I need to upgrade.
  • 11/11/2009 10:11 PM In reply to

    Re: DirectX 10 2D text issue

    I have had the same problem with 3D polygons, 2d-sprites and text. the cause was BlendState. So before drawning sprites (polygons are already rendered) and text you need to save current blendstate, set transparent, draw sprites and set original blendstate. My code: 
    HRESULT PrintText(LPCWSTR lpText, D3DXCOLOR TextColor) {  
        FLOAT OriginalBlendFactor[4];  
        UINT OriginalSampleMask = 0;  
        ID3D10BlendState* pFontBlendState10=NULL; // for blending  
        ID3D10BlendState* pOriginalBlendState10=NULL;  
     
        // Save the current blend state  
        g_pd3dDevice->OMGetBlendState(&pOriginalBlendState10, OriginalBlendFactor, &OriginalSampleMask);  
        // Set the blend state for font drawing  
        if(pFontBlendState10) {  
            FLOAT NewBlendFactor[4] = {0,0,0,0};  
            g_pd3dDevice->OMSetBlendState(pFontBlendState10, NewBlendFactor, 0xffffffff);  
        }  
          
        // Create and Initialize the destination rectangle  
        RECT rc;  
        SetRectEmpty(&rc);  
        // Use the GetFontRectangle helper function to get the proper size of the rectangle.  
        GetFontRectangle(lpText, &rc);  
        // Start font drawing  
        g_pFontSprite->Begin(D3DX10_SPRITE_SORT_TEXTURE);  
        // Draw the text to the screen  
        HRESULT hr = g_pFont->DrawText( NULL, lpText, -1, &rc, DT_LEFT, TextColor);  
        g_pFontSprite->End();  
        // Restore the previous blend state  
        g_pd3dDevice->OMSetBlendState(pOriginalBlendState10, OriginalBlendFactor, OriginalSampleMask);  
        return hr;    
    another explanation of this problem was given by davie732 (calling inputlayout and buffers in every frame, not only at initializatiion)
Page 1 of 1 (8 items) Previous Next