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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include <Windows.h>
#include<iostream>
#include "d3d9.h"
using namespace std;
#pragma comment( lib,"d3d9.lib")
LRESULT CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam);
class manageWindow
{
private:
HWND hWnd;//handler window
bool closeWindow ;
public:
manageWindow();
void createWindow(HINSTANCE hInstance);
//HWND getHwnd() ;
bool getCloseWindow();
void setCloseWindow(bool myBoolValue);
};
manageWindow *myWindow ;
HWND hWnd;//handler window
class direct3dApp
{
private :
//manageWindow myWindow ;
IDirect3D9 *D3dDevice ;//cré un device
IDirect3DDevice9 *myIDirect3DDevice9 ;
public:
direct3dApp();
void deviceCreation();
void rendering();
void freeD3d();//mettre un destructeur a la place
};
direct3dApp::direct3dApp()
{
D3dDevice=NULL;
myIDirect3DDevice9=NULL ;
D3dDevice = Direct3DCreate9(D3D_SDK_VERSION);
/*if(!D3dDevice)
{
//Handle error
}*/
}
void direct3dApp::deviceCreation()
{
D3DFORMAT format=D3DFMT_A8R8G8B8;//D3DFMT_R5G6B5;
D3DPRESENT_PARAMETERS presentParameters;
HRESULT hResult;
//met à zéro tout les champs du pointeur sur structure
ZeroMemory(&presentParameters,sizeof(D3DPRESENT_PARAMETERS));
presentParameters.BackBufferCount= 1; presentParameters.MultiSampleType=D3DMULTISAMPLE_NONE; presentParameters.MultiSampleQuality=0;
presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
presentParameters.hDeviceWindow = hWnd; presentParameters.Flags=0;
presentParameters.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;
presentParameters.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
presentParameters.BackBufferFormat=format; //Display format
presentParameters.EnableAutoDepthStencil=FALSE;
hResult=D3dDevice->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
&presentParameters,
&myIDirect3DDevice9);
if(FAILED(hResult))
{}
}
void direct3dApp::rendering()
{
myIDirect3DDevice9->Clear(0, NULL,
D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER, 0x000000EE, //Colour to clear to (AARRGGBB)
1.0f, 0 );
myIDirect3DDevice9->BeginScene() ;
myIDirect3DDevice9->EndScene() ;
myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);
}
void direct3dApp::freeD3d()
{
if(D3dDevice)
{
D3dDevice->Release();
D3dDevice=NULL;
}
}
/*HWND manageWindow::getHwnd()
{
return hWnd ;
}*/
manageWindow::manageWindow()
{
closeWindow=false ;
}
bool manageWindow::getCloseWindow()
{
return closeWindow ;
}
void manageWindow::setCloseWindow(bool myBoolValue)
{
closeWindow = myBoolValue ;
}
void manageWindow::createWindow(HINSTANCE hInstance)
{
WNDCLASS hWindow;
//hWindow.cbSize=sizeof(WNDCLASSEX);
hWindow.style=CS_HREDRAW|CS_VREDRAW;
hWindow.lpfnWndProc=MainProc;
hWindow.cbClsExtra=0;
hWindow.cbWndExtra=0;
hWindow.hInstance=hInstance;
hWindow.hIcon=LoadIcon(NULL,IDI_APPLICATION);
hWindow.hCursor=LoadCursor(NULL,IDC_ARROW);
hWindow.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
hWindow.lpszMenuName=NULL;
hWindow.lpszClassName="stdWindow";
//hWindow.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
RegisterClass(&hWindow);
int wWidth=GetSystemMetrics(SM_CXSCREEN);//window width= resolution du bureau
int wHeight=GetSystemMetrics(SM_CYSCREEN);
HWND hWnd;//handler window
hWnd=CreateWindow(
"stdWindow",
"DirectX",
WS_POPUP|WS_VISIBLE ,
0,
0,//(0,0) origine en haut à gauche
wWidth,
wHeight,//résolution du bureau
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hWnd,SW_SHOW);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
myWindow = new manageWindow() ;
direct3dApp *myDirect3dApp = new direct3dApp() ;
myWindow->createWindow(hInstance);
ShowCursor(FALSE);
myDirect3dApp->deviceCreation();
MSG msg;
while(1)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
myDirect3dApp->rendering();
if( myWindow->getCloseWindow() )
return 0;
}
}
LRESULT CALLBACK MainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT paintst;
switch (message)
{
/*case WM_PAINT:
hDC=BeginPaint(hWnd,&paintst);
EndPaint(hWnd,&paintst);
return 0;*/
case WM_KEYDOWN:
case WM_DESTROY:
myWindow->setCloseWindow(true) ;
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} |
Partager