Directx09 创建窗口代码
2016-12-07 11:13
148 查看
#include"d3d9.h" #include"d3dx9.h" //-------------------------global variables--------- LPDIRECT3D9 g_pD3D=NULL; LPDIRECT3DDEVICE9 g_pd3dDevice=NULL; VOID Cleanup() { if( g_pd3dDevice != NULL) g_pd3dDevice->Release(); if( g_pD3D != NULL) g_pD3D->Release(); } HRESULT Init(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 Render() { // Clear the back buffer to a blue color g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene g_pd3dDevice->BeginScene(); // Rendering of scene objects happens here // End the scene g_pd3dDevice->EndScene(); g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); } LRESULT WINAPI MsgProc( 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; } return DefWindowProc( hWnd, msg, wParam, lParam ); } INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) { // Register the window class. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "Direct3D Tutorial", NULL }; RegisterClassEx( &wc ); // Create the application's window. HWND hWnd = CreateWindow( "Direct3D Tutorial", "Direct3D Tutorial 01: CreateDevice", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL ); if(SUCCEEDED(Init(hWnd))) { ShowWindow(hWnd,SW_SHOWNORMAL); UpdateWindow(hWnd); // The message loop. MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } }
相关文章推荐
- hook窗口的创建、销毁、焦点等事件(vb代码)
- 重定位代码,创建窗口,元旦快乐
- OpenGl Superbible示例代码中glfwCreateWindow不能成功创建窗口问题
- win32的创建窗口代码
- Cocoa系列教学一:使用代码创建窗口
- 【OpenGL】代码记录01创建窗口
- MFC代码创建窗口
- OpenGL1-创建窗口(建立Win32的OpenGL开发环境 )(代码上传)
- 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码)
- Cocoa系列教学一:使用代码创建窗口
- 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码)
- 创建窗口,使其能移动的代码
- [Cocoa]使用代码创建窗口
- QT编程入门--用代码创建简单的窗口
- 学MFC之前必须会的金典创建窗口程序的过程代码
- 重头再来——创建一个最基本的Windows窗口的代码
- 用最短的MFC代码创建一个窗口
- pyqt之使用QtCreator创建第一个简单的窗口(label、pushbutton以及非代码直接从图形界面选择的信号与槽)
- WINDOWS窗口创建及消息处理代码