AnswerBun.com

How to time draw images to the window in d3d8

Game Development Asked by kite on November 2, 2021

I need to be able to draw one image then have it disappear then draw the next image then disappear.
I can draw 1 image on the window but I can not make it disappear and draw image 2.
Also would be great too with some code examples makes it easier for me to read.
Any ideas here is my code.

HWND g_hWnd;                                // The application window.
IDirect3D8* g_Dx3D;                     
IDirect3DDevice8* g_d3dDevice;              //The one and only DirectX device
D3DDISPLAYMODE g_d3ddm;                     //Display Mode Capablity.


ID3DXSprite*        g_pSprite;              // The sprite instance
IDirect3DTexture8*  g_pTexture;             // Instance to hold the texture.
D3DXVECTOR2         g_position;             // Position of the sprite.
D3DXVECTOR2         g_velocity;             // Velocity of the sprite.


int APIENTRY WinMain(HINSTANCE hInstance,
                 HINSTANCE hPrevInstance,
                 LPSTR     lpCmdLine,
                 int       nCmdShow)
{
// TODO: Place code here.
InitDirect3d();
InitSprite1();

 MSG msg;
 // Main message loop:
 ZeroMemory( &msg, sizeof(msg) );
 while( msg.message!=WM_QUIT )
 {
    if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    else
        Render();
}

return msg.wParam;

return 0;
}


HRESULT Render()
{


g_d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

g_d3dDevice->BeginScene();
{
    g_pSprite->Begin();
    {
        g_pSprite->Draw(g_pTexture,NULL,NULL,NULL,0,&g_position,0xFFFFFFFF);
    }
    g_pSprite->End();


    g_pSprite->Begin();
    {
        g_pSprite->Draw(g_pTexture,NULL,NULL,NULL,0,&g_position,0xFFFFFFFF);
    }
    g_pSprite->End();
}
g_d3dDevice->EndScene();

g_d3dDevice->Present( NULL, NULL, NULL, NULL );

return S_OK;
}

*
Initialise the DirectX.
*/
HRESULT InitDirect3d()
{
do
{
    if(FAILED(InitWindow()))
    {
        break;
    }

    g_Dx3D = Direct3DCreate8( D3D_SDK_VERSION );

    if(g_Dx3D == NULL)
    {
        break;
    }

    if( FAILED( g_Dx3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_d3ddm ) ) )
    {
        break;
    }

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed   = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = g_d3ddm.Format;
    d3dpp.hDeviceWindow = g_hWnd;
    d3dpp.BackBufferWidth = WINDOW_WIDTH;
    d3dpp.BackBufferHeight = WINDOW_HEIGHT;
    d3dpp.BackBufferCount = 1;
    

    if( FAILED( g_Dx3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_d3dDevice ) ) )
    {
        break;
    }
    return S_OK;
} while(false);

return E_FAIL;
}


/*
Create the window that we will use to render the image.
*/
HRESULT InitWindow()
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, 
              GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
              "D3D Tutorial", NULL };
RegisterClassEx( &wc );

DWORD dwFrameWidth    = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight   = GetSystemMetrics( SM_CYSIZEFRAME );
DWORD dwMenuHeight    = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
DWORD dwWindowWidth   = WINDOW_WIDTH  + dwFrameWidth * 2;
DWORD dwWindowHeight  = WINDOW_HEIGHT + dwFrameHeight * 2 + 
                        dwMenuHeight + dwCaptionHeight;
// Create the application's window.
g_hWnd = CreateWindow( "D3D Tutorial", 
                          "test", 
                          
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_CLIPSIBLINGS|WS_VISIBLE, 
                          CW_USEDEFAULT, CW_USEDEFAULT, dwWindowWidth, dwWindowHeight,
                          GetDesktopWindow(), 
                          NULL, 
                          wc.hInstance, 
                          NULL );

if(g_hWnd == NULL)
{
    return(E_FAIL);
}

ShowWindow(g_hWnd, SW_SHOW);
UpdateWindow(g_hWnd);

return(S_OK);

}


/*
 Initialise the sprite.
 */
 HRESULT InitSprite1()
 {
 HRESULT logo1;

 logo1 = D3DXCreateTextureFromFile(g_d3dDevice,"backgorund.jpeg",&g_pTexture);

 g_position.x = 10;
 g_position.y = 10;

logo1 = D3DXCreateSprite(g_d3dDevice,&g_pSprite); 

return logo1;
}



LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) 
{
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

Add your own answers!

Related Questions

How do i draw a ray in unity

1  Asked on January 7, 2022 by levent

   

testPoint not working – libgdx

1  Asked on January 5, 2022 by ngc-qu-nguyn

   

C# Increase move speed for spawned objects

1  Asked on January 5, 2022 by jenkatan29

   

Rotate vector by matrix?

2  Asked on December 29, 2021

         

Finding all possible paths from one hexagon to another

3  Asked on December 25, 2021 by vitozz_rdx

 

Unity : apk vs aab for the same scene

0  Asked on December 23, 2021

   

Unreal Engine custom camera

0  Asked on December 23, 2021

     

(Tiled) Background stops being rendered in libGDX

1  Asked on December 21, 2021 by xmac

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir