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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| #include "Windows.h"
#include "D3D9.h"
#include <mmsystem.h>
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LRESULT CALLBACK MainProc(HWND hWnd, UINT mes, WPARAM wParam, LPARAM lParam);
HRESULT InitD3D(HWND hWnd);
void rendu(void);
void destruction(void);
void viewport(void);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX fenetre;
fenetre.cbSize=sizeof(WNDCLASSEX);
fenetre.style=CS_HREDRAW|CS_VREDRAW;
fenetre.lpfnWndProc=MainProc;
fenetre.cbClsExtra=0;
fenetre.cbWndExtra=0;
fenetre.hInstance=hInstance;
fenetre.hIcon=LoadIcon(NULL,IDI_APPLICATION);
fenetre.hCursor=LoadCursor(NULL,IDC_ARROW);
fenetre.hbrBackground=reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
fenetre.lpszMenuName=NULL;
fenetre.lpszClassName="std";
fenetre.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&fenetre);
HWND hWnd;
hWnd=CreateWindowEx( WS_EX_CLIENTEDGE,"std","fenêtre",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (SUCCEEDED (InitD3D(hWnd)))
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow( hWnd );
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
LRESULT CALLBACK MainProc(HWND hWnd, UINT mes, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT paintst;
switch (mes)
{
case WM_PAINT:
rendu();
hDC=BeginPaint(hWnd,&paintst);
EndPaint(hWnd,&paintst);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, mes, wParam, lParam);
}
}
HRESULT InitD3D(HWND hWnd)
{
if (NULL == (g_pD3D = Direct3DCreate9( D3D_SDK_VERSION)))
return E_FAIL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
return S_OK;
}
void rendu(void)
{
if (NULL==g_pd3dDevice)
return;
g_pd3dDevice->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
if (SUCCEEDED (g_pd3dDevice->BeginScene()))
{
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
void destruction(void)
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}
void viewport(void)
{
} |
Partager