Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


JeZ-l-Lee

Member Since 03 Jul 2010
Offline Last Active Oct 28 2014 09:07 AM

Posts I've Made

In Topic: DirectX 9.0c: DrawTextA() Onto DirectX Texture?

14 November 2013 - 01:50 PM

Hi,

 

I've been trying without success to do the following:

(1) Create a DirectX 9 texture

(2) Render a loaded Button.png texture onto the created DirectX 9 texture

(3) Render TTF text on top of the rendered Button.png texture on the created DirectX 9 texture

(4) Render the new button with text DirectX 9 texture to the screen

 

Code is below, any help would be greatly appreciated...

(Sprites[1000] is the loaded Button.png texture)

 

JeZ+Lee

char buttonText[256];
if (index > 1000 && index < 1008)
{
    LPDIRECT3DSURFACE9 backBuffer = NULL;
    DXDevice->GetRenderTarget(0, &backBuffer);

    DXDevice->CreateTexture(Sprites[1000].OriginalWidth, Sprites[1000].OriginalHeight, 0, D3DUSAGE_RENDERTARGET,
                            D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &Sprites[index].Texture, NULL);

    LPDIRECT3DSURFACE9 pRenderSurface = NULL;
    Sprites[index].Texture->GetSurfaceLevel(0, &pRenderSurface);
    DXDevice->SetRenderTarget(0, pRenderSurface);

    if (index == 1001)  strcpy_s(buttonText, "START!");
    if (index == 1002)  strcpy_s(buttonText, "Options");
    if (index == 1003)  strcpy_s(buttonText, "How To Play");
    if (index == 1004)  strcpy_s(buttonText, "High Scores");
    if (index == 1005)  strcpy_s(buttonText, "About");
    if (index == 1006)  strcpy_s(buttonText, "Exit");
    if (index == 1007)  strcpy_s(buttonText, "Back");

    DXDevice->BeginScene();

    DXDevice->SetTexture(0, Sprites[index].Texture);

    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
                              (float)Sprites[1000].OriginalWidth / (float)Sprites[1000].OriginalHeight, 0.1f, 100.0f );

    DXDevice->SetTransform( D3DTS_PROJECTION, &matProj );

    Sprites[1000].DXSprite->Begin(D3DXSPRITE_ALPHABLEND);

    DXDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
    DXDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
    DXDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC);

    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = Sprites[1000].TextureHeight;
    spriteRect.right = Sprites[1000].TextureWidth;

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f;
    spritePosition.y = 0.0f;
    spritePosition.z = 0.0f;

    D3DXMATRIX matrixSpriteTransform;

    D3DXVECTOR2 screenPostion = D3DXVECTOR2(0, 0);

    float rotation = 0.0f;

    D3DXVECTOR2 scaling(1.0f, 1.0f);

    D3DXMatrixTransformation2D(&matrixSpriteTransform, NULL, 0.0, &scaling, NULL, rotation, &screenPostion);
    Sprites[1000].DXSprite->SetTransform(&matrixSpriteTransform);

    Sprites[1000].DXSprite->Draw( Sprites[1000].Texture, &spriteRect, NULL, &spritePosition,
                                  D3DCOLOR_RGBA(Sprites[1000].RedHue, Sprites[1000].GreenHue, Sprites[1000].BlueHue,
                                  Sprites[1000].Transparency) );

    Sprites[1000].DXSprite->End();

    D3DXMATRIX matrixFixTextAfterSpriteDrawing;
    D3DXMatrixTransformation2D(&matrixFixTextAfterSpriteDrawing, NULL, NULL, NULL, NULL, NULL, NULL);
    D3DXMatrixIdentity(&matrixFixTextAfterSpriteDrawing);

    RECT rect, textSize;
    int posX, posY;

    Font[0]->DrawTextA( NULL, buttonText, -1, &textSize, DT_CALCRECT, D3DCOLOR_RGBA(255, 255, 255, 255) );

    posX = (Sprites[1000].OriginalWidth / 2) - (textSize.right / 2);
    posY = (Sprites[1000].OriginalHeight / 2);

    for (int screenY = -2; screenY < 3; screenY++)
    {
        for (int screenX = -2; screenX < 3; screenX++)
        {
            SetRect( &rect, posX+screenX, posY+screenY, 0, 0 );
            if (screenY != 0 && screenX != 0)
                Font[0]->DrawTextA(NULL, buttonText, -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(100, 100, 100, 255) );
        }
    }

    SetRect( &rect, posX, posY, 0, 0 );
    Font[0]->DrawTextA( NULL, buttonText, -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(255, 255, 255, 255) );

    DXDevice->EndScene();

    pRenderSurface->Release();

    DXDevice->SetRenderTarget(0, backBuffer);

    D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 800.0f / 480.0f, 0.1f, 100.0f );
    DXDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}


In Topic: DirectX 9.0c: Handling "Lost Device"?

09 November 2013 - 06:51 PM

Hi,

 

My DirectX app does not currently support full screen mode.

In windowed mode, how would I cause my DirectX app to lose its device

so that I can test my lost device handling source code to see if it works?

 

Thanks!

 

JeZ+Lee


In Topic: DirectX 9.0c: Handling "Lost Device"?

09 November 2013 - 12:54 PM

Hi,

 

Thanks for all the replies and information...

 

I don't think I will be implementing a full screen option.

(just current maximize window button option)

 

So the DirectX device can never get lost in windowed mode?

Let me know, thanks!

 

JeZ+Lee


In Topic: Can't Render Sprites & TTF Text At Same Time?

04 November 2013 - 07:41 PM

Hi,

 

Got it working!

 

Added:

   D3DXMATRIX matrixFixTextAfterSpriteDrawing;
   D3DXMatrixTransformation2D(&matrixFixTextAfterSpriteDrawing, NULL, NULL, NULL, NULL, NULL, NULL);
   D3DXMatrixIdentity(&matrixFixTextAfterSpriteDrawing);

to top of text render function.

 

Thank you for your help!

 

JeZ+Lee


In Topic: Can't Render Sprites & TTF Text At Same Time?

04 November 2013 - 07:01 PM

I bet that it isn't actually the D3DXMatrixTransformation2D that is the problem.

 

In my opinion the problem is that you set a transform matrix with the function SetTransform(...)

 

Since the Direct3D is a state machine, you'll need to restore a proper transform matrix before using the text function, since they seem to be affected by a transform.

 

The transform matrix that you'll need to set before drawing text is probably an identity matrix.

 

Cheers!

Hi,

 

Thank you for your reply.

 

I changed the source code of the text render function to below, but it still does not display?

 

What am I doing wrong?

 

JeZ+Lee

void Visuals::DrawTextOntoScreenBuffer(const char *textToDisplay, LPD3DXFONT Font, int posX, int posY,
                                       int XJustification, int textRed, int textGreen, int textBlue,
                                       int outlineRed, int outlineGreen, int outlineBlue)
{
RECT rect, textSize;

    D3DXMATRIX matrixFixTextAfterSpriteDrawing;
    matrixFixTextAfterSpriteDrawing._11 = 1;
    matrixFixTextAfterSpriteDrawing._12 = 0;
    matrixFixTextAfterSpriteDrawing._13 = 0;
    matrixFixTextAfterSpriteDrawing._14 = 0;
    matrixFixTextAfterSpriteDrawing._21 = 0;
    matrixFixTextAfterSpriteDrawing._22 = 1;
    matrixFixTextAfterSpriteDrawing._23 = 0;
    matrixFixTextAfterSpriteDrawing._24 = 0;
    matrixFixTextAfterSpriteDrawing._31 = 0;
    matrixFixTextAfterSpriteDrawing._32 = 0;
    matrixFixTextAfterSpriteDrawing._33 = 1;
    matrixFixTextAfterSpriteDrawing._34 = 0;
    matrixFixTextAfterSpriteDrawing._41 = 0;
    matrixFixTextAfterSpriteDrawing._42 = 0;
    matrixFixTextAfterSpriteDrawing._43 = 0;
    matrixFixTextAfterSpriteDrawing._44 = 1;
    D3DXMatrixIdentity(&matrixFixTextAfterSpriteDrawing);

    Font[0].DrawTextA( NULL, textToDisplay, -1, &textSize, DT_CALCRECT, D3DCOLOR_RGBA(textRed, textGreen, textBlue, 255) );

    if (XJustification == JustifyLeft)
    {
        // Do nothing...
    }
    else if (XJustification == JustifyCenter)
    {
        posX = (800 / 2) - (textSize.right / 2) - 3;
    }
    else if (XJustification == JustifyRight)
    {
        posX = (800 - posX) - textSize.right - 3;
    }
    else if (XJustification == JustifyCenterOnPoint)
    {
        posX = posX - (textSize.right / 2) - 3;
    }

    for (int screenY = -2; screenY < 3; screenY++)
    {
        for (int screenX = -2; screenX < 3; screenX++)
        {
            SetRect( &rect, posX+screenX, posY+screenY, 0, 0 );
            if (screenY != 0 && screenX != 0)
                Font[0].DrawTextA( DXSpriteForTextOutline, textToDisplay, -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(outlineRed, outlineGreen, outlineBlue, 255) );
        }
    }

    SetRect( &rect, posX, posY, 0, 0 );
    Font[0].DrawTextA( DXSpriteForText, textToDisplay, -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(textRed, textGreen, textBlue, 255) );
}


PARTNERS