http://aoisensi.blogspot.jp/2012/05/cdirectx_22.html
#pragma comment(lib, "d3d9.lib") #include<windows.h> #include<TCHAR.h> #include<d3d9.h> LPDIRECT3D9 g_pD3D = NULL; LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); void Render(); void Cleanup(); HRESULT InitD3D( HWND ); int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd) { HWND hWnd; MSG msg; WNDCLASS wc; //①ウィンドウクラスの定義・登録 wc.style = CS_HREDRAW | CS_VREDRAW; //スタイル wc.lpfnWndProc = WndProc; //メッセージ処理関数 wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst; //プログラムのハンドル wc.hIcon = NULL; //アイコン wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //カーソル wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); //背景色 wc.lpszMenuName = NULL; //メニュー wc.lpszClassName = _T("test"); //クラス名 if( !RegisterClass( &wc ) ) { return 0; } //②ウィンドウの作成 hWnd = CreateWindow( _T("test"), _T("Test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL ); //③ウィンドウを表示 if( SUCCEEDED( InitD3D( hWnd ) ) ) { ShowWindow( hWnd, nShowCmd ); UpdateWindow( hWnd ); //④メインループ while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } UnregisterClass( _T("D3D Tutorial"), wc.hInstance ); return 0; } LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_DESTROY: Cleanup(); PostQuitMessage( 0 ); return 0; case WM_PAINT: Render(); ValidateRect( hWnd, NULL ); return 0; default: return( DefWindowProc( hWnd, msg, wParam, lParam) ); } } void Render() { if( NULL == g_pd3dDevice ) { return; } g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0x00, 0x00, 0xFF), 1.0f, 0 ); if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } void Cleanup() { if( g_pd3dDevice != NULL) { g_pd3dDevice->Release(); } if ( g_pD3D != NULL) { g_pD3D->Release(); } } 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; }
メモ程度なので、コメントは残していません
0 件のコメント:
コメントを投稿