|
|
已经生成。exe文件了,可以打开甚么反映也没有,像以前刚学C的时候用TC程序会一闪而过那样-__-!!!!
#include <d3d9.h>
LPDIRECT3D9 g_pD3D = NULL; // Direct3D对象指针
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Direct3D设备指针
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// 查询当前的显示模式信息
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
//设置传递给LPDIRECT3D9::CreateDevice的参数
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: 释放系统资源
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: progrma main loop, Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
if( NULL == g_pd3dDevice )
return;
// 将后缓冲区置为蓝色
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
g_pd3dDevice->BeginScene();
// 这里加入图形绘制程序
g_pd3dDevice->EndScene();
g_pd3dDevice-> resent( NULL, NULL, NULL, NULL );
}
//-----------------------------------------------------------------------------
// Desc: 窗口过程函数
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{ switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: 应用程序入口
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// 注册窗口类
WNDCLASS wndclass = { 0, MsgProc, 0L, 0L, hInst,
NULL, NULL, NULL, NULL,"D3D Tutorial" };
RegisterClass( &wndclass );
// Create the application's window
HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial : CreateDevice",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, wndclass.hInstance, NULL );
// 初始化Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
// 释放系统资源,退出
Cleanup();
UnregisterClass( "D3D Tutorial", wndclass.hInstance );
return 0;
}
[em17] |
|