1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| #include "windows.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <dxerr9.h>
BOOL Init_D3D (HWND hWnd)
{
LPDIRECT3D9 g_objetD3D;
g_objetD3D = Direct3DCreate9( D3D_SDK_VERSION );
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(D3DPRESENT_PARAMETERS) );
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.hDeviceWindow = NULL;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
d3dpp.Windowed=TRUE;
d3dpp.FullScreen_RefreshRateInHz=75;
LPDIRECT3DDEVICE9 g_peripherique3D;
HRESULT hr;
hr= g_objetD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_peripherique3D );
LPD3DXSPRITE g_routinesSprites;
D3DXCreateSprite(g_peripherique3D,&g_routinesSprites);
LPDIRECT3DTEXTURE9 image;
D3DXCreateTextureFromFile(g_peripherique3D, "fond.bmp", &image);
g_peripherique3D->BeginScene();
g_peripherique3D->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0, 0);
g_routinesSprites->Draw(image, NULL, NULL, NULL, 0xFFFFFFFF);
g_peripherique3D->EndScene();
g_peripherique3D->Present(NULL, NULL, NULL, NULL);
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message)
{
case WM_KEYDOWN :
PostQuitMessage(0);
break;
case WM_DESTROY :
PostQuitMessage(0); // ici, on intercepte le message de destruction
break;
case WM_PAINT : // dessin de la zone client de l'application
{
PAINTSTRUCT PaintStruct;
HDC PaintDC=BeginPaint( hwnd, &PaintStruct );
EndPaint( hwnd, &PaintStruct );
}
break;
}
return DefWindowProc( hwnd, message, wParam, lParam );
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpszCmpParam,int nCmdShow)
{
WNDCLASS W; // structure de classe de fenêtre
HWND hwnd;
LPSTR Name = "Ball Of Duty";
MSG msg;
// remplissage de la structure de classe
memset( &W, 0, sizeof(WNDCLASS) );
W.style = CS_HREDRAW | CS_VREDRAW;
W.hInstance = hInst;
W.lpszClassName = Name;
W.hbrBackground =(HBRUSH)(COLOR_WINDOW+4);
W.lpfnWndProc = WndProc; // lien vers la procédure de fenêtre
RegisterClass( &W ); // enregistrement dans Windows de la structure
// Création de la fenêtre avec toutes les options nécessaires (taille = taille de l'écran)
hwnd = CreateWindowEx( 0, Name, Name, WS_POPUP, 0, 0,
GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ),
NULL, NULL, hInst, NULL );
// Affichage de la fenêtre
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
Init_D3D(hwnd);
// On efface le curseur
ShowCursor( false );
// Boucle d'écoute des messages
while( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
} |
Partager