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
| BOOL CWinStars2App::OnIdle(LONG lCount)
{
CWinApp::OnIdle(lCount);
// TODO: Add your specialized code here and/or call the base class
AfxGetMainWnd()->Invalidate(FALSE);
return TRUE;
}
void CWinAppl::OnDraw(CDC* pDC)
{
CWinStars2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
render();
}
bool CWinApp::Render()
{
_device->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L);
if (!FAILED(_device->BeginScene()))
{
_device->EndScene();
}
_device->Present(NULL,NULL,NULL,NULL);
}
bool Graphics::DefinitionMode(D3DPRESENT_PARAMETERS &d3dpp, int width, int height)
{
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
if(FAILED( _d3d9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
{
return false;
}
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferWidth=width;
d3dpp.BackBufferHeight=height;
d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz=0;
d3dpp.BackBufferCount=1;
d3dpp.MultiSampleType= D3DMULTISAMPLE_NONE;
switch(Antialiasing)
{
case 2 : d3dpp.MultiSampleType= D3DMULTISAMPLE_2_SAMPLES; break;
case 4 : d3dpp.MultiSampleType= D3DMULTISAMPLE_4_SAMPLES; break;
}
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;// D3DFMT_D16 - D3DFMT_D24S8
return true;
}
bool Graphics::create(
HWND hwnd,
int width,
int height,
bool windowed)
{
// Create the D3D object.
if((_d3d9 = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
{
return false;
}
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
if (!DefinitionMode(d3dpp, width, height)) return false;
// Create the D3DDevice
if(FAILED(_d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING ,
&d3dpp, &_device)))
{
return false;
}
return true;
} |
Partager