Jump to content

  • Log In with Google      Sign In   
  • Create Account

JeZ-l-Lee

Member Since 03 Jul 2010
Offline Last Active May 06 2014 02:24 AM

#5106945 Can't Render Sprites & TTF Text At Same Time?

Posted by JeZ-l-Lee on 04 November 2013 - 11:26 AM

Hi,

 

Working on a 2D DirectX 9.0c game engine now.

I am working on graphics core.

 

Problem I have now is that I can't seem to render sprites and TTF text simultaneously?

I can render sprites and I can render TTF texts separately, but when I try to do both I only get sprites?

 

Hope someone can help, thanks!

 

JeZ+Lee

 

Here is the relevant source code: 

void Visuals::DrawSpriteOntoScreenBuffer(int index)
{
    Sprites[index].DXSprite->Begin(D3DXSPRITE_ALPHABLEND);

    if (Sprites[index].Smooth == false)
    {
        DXDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
        DXDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
        DXDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
    }
    else if (Sprites[index].Smooth == true)
    {
        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[index].TextureHeight;
    spriteRect.right = Sprites[index].TextureWidth;

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f - (Sprites[index].TextureWidth/2);
    spritePosition.y = 0.0f - (Sprites[index].TextureHeight/2);
    spritePosition.z = 0.0f;

    D3DXMATRIX matrixSpriteTransform;

    D3DXVECTOR2 screenPostion = D3DXVECTOR2(Sprites[index].ScreenX, Sprites[index].ScreenY);

    float rotation = Sprites[index].RotationDegree * (3.14159265f/180.0f);

    if (Sprites[index].FlipX == true)  Sprites[index].ScaleX = (Sprites[index].ScaleX*-1.0f);
    if (Sprites[index].FlipY == true)  Sprites[index].ScaleY = (Sprites[index].ScaleY*-1.0f);
    D3DXVECTOR2 scaling(Sprites[index].ScaleX, Sprites[index].ScaleY);
    if (Sprites[index].FlipX == true)  Sprites[index].ScaleX = (Sprites[index].ScaleX*-1.0f);
    if (Sprites[index].FlipY == true)  Sprites[index].ScaleY = (Sprites[index].ScaleY*-1.0f);

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

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

    Sprites[index].DXSprite->End();
}

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;

    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( NULL, textToDisplay, -1, &rect, DT_NOCLIP, D3DCOLOR_RGBA(outlineRed, outlineGreen, outlineBlue, 255) );
        }
    }

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

void Visuals::DisplayScreenBufferOntoDisplay(void)
{
    DXDevice->EndScene();
    DXDevice->Present( NULL, NULL, NULL, NULL );

    DXDevice->BeginScene();
}
void Screens::ApplyScreenFadeTransition(void)
{
    if (ScreenTransitionStatus == FadeIn)
    {
        if (ScreenFadeTransparency > 0)
        {
            ScreenFadeTransparency -= 1;
            ScreenIsDirty = true;
        }
        else
        {
            ScreenFadeTransparency = 0;
            ScreenTransitionStatus = FadeNone;
        }
    }
    else if (ScreenTransitionStatus == FadeOut)
    {
        if (ScreenFadeTransparency < 255)
        {
            ScreenFadeTransparency += 1;
            ScreenIsDirty = true;
        }
        else
        {
            ScreenFadeTransparency = 255;
            ScreenTransitionStatus = FadeAll;
        }
    }

    if (ScreenTransitionStatus != FadeNone)
    {
        visuals->Sprites[0].ScreenX = 400;
        visuals->Sprites[0].ScreenY = 240;
        visuals->Sprites[0].Transparency = ScreenFadeTransparency;
        visuals->DrawSpriteOntoScreenBuffer(0);
    }
}

void Screens::ProcessScreenToDisplay(void)
{
    switch(ScreenToDisplay)
    {
        case SixteenBitSoftScreen:
            DisplaySixteenBitSoftScreen();
            break;

        case TitleScreen:
            DisplayTitleScreen();
            break;

        default:
            break;
    }

    ApplyScreenFadeTransition();

    if (ScreenIsDirty == true)
    {
        visuals->DisplayScreenBufferOntoDisplay();
        if (ScreenTransitionStatus != FadeIn && ScreenTransitionStatus != FadeOut)  ScreenIsDirty = false;
    }
}

void Screens::DisplaySixteenBitSoftScreen(void)
{
    if (ScreenTransitionStatus == FadeAll)
    {
        ScreenDisplayTimer = 370;
        ScreenTransitionStatus = FadeIn;
    }

    if (ScreenIsDirty == true)
    {
        visuals->ClearScreenBufferWithColor(0, 0, 0, 255);

        visuals->Sprites[5].ScreenX = 400;
        visuals->Sprites[5].ScreenY = 210;
        visuals->Sprites[5].ScaleX = 5.0;
        visuals->Sprites[5].ScaleY = 8.0;
        visuals->Sprites[5].Smooth = false;
        visuals->DrawSpriteOntoScreenBuffer(5);

        visuals->DrawTextOntoScreenBuffer("TM", visuals->Font[0], 55, 295, JustifyRight, 1, 255, 1, 1, 1, 1);

        visuals->DrawTextOntoScreenBuffer("Bringing back old memories from the 16bit era!", visuals->Font[0], 0, 307, JustifyCenter, 1, 255, 1, 1, 1, 1);

        visuals->DrawTextOntoScreenBuffer("www.16BitSoft.com", visuals->Font[0], 0, 347, JustifyCenter, 1, 255, 1, 1, 90, 1);
    }

    if (ScreenTransitionStatus == FadeOut && ScreenFadeTransparency == 255)
    {
        ScreenTransitionStatus = FadeAll;
        ScreenToDisplay = TitleScreen;
    }
}




#5106552 "D3DXMatrixTransformation2D": Rotation Not In Degrees?

Posted by JeZ-l-Lee on 02 November 2013 - 03:21 PM

Hi,

 

Thanks, I got it working...

 

JeZ+Lee




#5106545 "D3DXMatrixTransformation2D": Rotation Not In Degrees?

Posted by JeZ-l-Lee on 02 November 2013 - 03:00 PM

Hi,

 

I am designing a 2D game engine using DirectX 9.0c.

Currently I am working on graphics core.

 

My question now is the following:

"D3DXMatrixTransformation2D" rotation function perimeter does not seem to be in degrees?

How do I change it into degrees? (0'-360')

(see source code below)

 

Thanks!

 

JeZ+Lee

 

Here is the source:

//-------------------------------------------------------------------------------------------------------------------------------
void render( void )
{
    float x = 400; // Test value
    float y = 240; // Test value

    DXDevice->BeginScene();

    DXDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

    Sprite->Begin(D3DXSPRITE_ALPHABLEND);

    D3DSURFACE_DESC textureInfo;
    SpriteTexture->GetLevelDesc(0, &textureInfo);
    float spriteWidth = (float)textureInfo.Width;
    float spriteHeight = (float)textureInfo.Height;
    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = textureInfo.Height;
    spriteRect.right = textureInfo.Width;

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f - (spriteWidth/2);
    spritePosition.y = 0.0f - (spriteHeight/2);
    spritePosition.z = 0.0f;

    D3DXMATRIX matrixSpriteTransform;

//    D3DXVECTOR2 spriteCentre = D3DXVECTOR2(spriteWidth/2, spriteHeight/2);

    D3DXVECTOR2 screenPostion = D3DXVECTOR2(x, y);

    float rotation = 0.0f; //<--- How to change to degrees ???

    D3DXVECTOR2 scaling(1.0f, 1.0f);

    D3DXMatrixTransformation2D(&matrixSpriteTransform, NULL, 0.0, &scaling, /*&spriteCentre*/NULL, rotation, &screenPostion);
    Sprite->SetTransform(&matrixSpriteTransform);

    Sprite->Draw( SpriteTexture, &spriteRect, NULL, &spritePosition, D3DCOLOR_RGBA(255,255,255,255) );

    Sprite->End();

    DXDevice->EndScene();
    DXDevice->Present( NULL, NULL, NULL, NULL );
}

//-------------------------------------------------------------------------------------------------------------------------------




#5106080 DirectX 9: Best Method To Limit FPS?

Posted by JeZ-l-Lee on 31 October 2013 - 04:38 PM

You can just enable VSYNC. It will limit you to the refresh rate of the monitor, and prevent tearing.

Hi,
 
Thank you for the reply.
 
This sounds good, but can the video card driver override the game's VSYNC setting?
(meaning if the VSYNC is turned off in the video card driver then it won't be on in the game?)
 
Thanks!
 
JeZ+Lee



#5106071 DirectX 9: Best Method To Limit FPS?

Posted by JeZ-l-Lee on 31 October 2013 - 04:02 PM

Why do you want to limit fps? To avoid rendering faster than 60fps? To save energy (i.e. battery/electricity bill)? to be friendly with other programs?

Hi,

 

I just want the game engine to run at a constant 60 Frames Per Second on any computer.

I've been programming 2D video games for 15+ years and I have always limited the FPS.

(I realize this may *not * be the best method, but it's what I feel comfortable with)

 

JeZ+Lee

 

Click HERE for developer screenshot!




#5106059 DirectX 9: Best Method To Limit FPS?

Posted by JeZ-l-Lee on 31 October 2013 - 03:20 PM

Hi,

 

I'm developing a DirectX 9.0c 2D game engine now code named: "X-Caliber Engine"...

 

What is the best method to limit Frames Per Second?

 

I am currently doing this but I don't like it:

#include <mmsystem.h>
//...
static DWORD LastFrameTime = 0;
DWORD FPSLimit = 60;
//...

//-MAIN-LOOP--------------------------------------------------------------------
{
    render();

    DWORD currentTime = timeGetTime();
    if ( (currentTime - LastFrameTime) < (1000 / FPSLimit) )
    {
        Sleep(currentTime - LastFrameTime);
    }
    LastFrameTime = currentTime;
}

//--------------------------------------------------------------------MAIN-LOOP-

Above code adds an additional LIB dependency: "winmm.lib" which I don't like.

Any suggestions would be appreciated, thanks!

 

JeZ+Lee




#4814764 Making The Computer Play Checkers...

Posted by JeZ-l-Lee on 23 May 2011 - 03:33 PM

Hi,

My team and I are working on a checkers game called: "Checkers Genius 2".

Was hoping some people can play with the current alpha version
and provide suggestions or comments about our progress.
(both Windows® and Linux versions are currently available)

This game is open-source too, so if you care to look at the source
then feel completely free to download it!
( game engine uses: SDL1.2+OpenGL® )

Click Here To Visit Official Web Page
(information / screenshots / downloads / source)

Here are some screenshots:
Posted ImagePosted Image
Thanks!

JeZ+Lee


#4807174 "TetriCrisis 3 100% C.P.U." Open-Source Cross-Platform...

Posted by JeZ-l-Lee on 05 May 2011 - 06:04 PM

"TetriCrisis 3 100% C.P.U." Open-Source Cross-Platform...
Free source code to finished game!

Click here for official website!
(download the Linux version at bottom of above page for full source code)

Technology used is:
S.D.L. 1.2 / SDL_image / SDL_mixer / SDL_ttf / OpenGL®

Game runs on all Windows® and all Linux OS desktops, notebooks, and netbooks...
Posted ImagePosted Image

http://www.youtube.com/watch?v=Tk5xnY8YuK4

Enjoy!

JeZ+Lee
16BitSoft
Video Game Design Studio
www.16BitSoft.com


PARTNERS