Lesson 1: Getting Started with Direct3D #include // 헤더 // 라이브러리 include the Direct3D Library file #pragma comment ( lib, "d3d9.lib") // 전역 정의 global declarations LPDIRECT3D9 d3d; // the pointer to our Direct3D interface LPDIRECT3DDEVICE9 returned_d3ddev; // the pointer to the device class // 함수 원형 fuctions prototype void initD3D(HWND hWnd); // 기초 설정 3디 초기화 sets up and initializes Direct3D void render_frame(void); // 사실화 단일 프레임 renders a single frame void cleanD3D(void); // 닫기와 메모리 해제 close Direct3D and releases memory // 윈도우 함수 원형 the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // 기초 설정 3디 초기화 sets up and initializes Direct3D // this function initializes and prepares Direct3D for use void initD3D(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface // presentation parameters d3dpp D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device informations ZeroMemory( &d3dpp, sizeof(d3dpp) ); // clear out the struct for use d3dpp.Windowed = TRUE; // program windowed , not fullscreen d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D // create a device class using this information // and information from the d3dpp struct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &returned_d3ddev); /* HRESULT CreateDevice( UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface); UINT Adapter, */ } // 사실화 단일 프레임 renders a single frame // In this function we will render a single frame // The frame will be rather simple, and will consist of a blue background void render_frame(void) { // clear the window to a deep blue returned_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,40,100), 1.0f, 0); // begins the 3d scene returned_d3ddev->BeginScene(); // do 3D rendering on the back buffer here // ends the 3d scene returned_d3ddev->EndScene(); // displays the created frame returned_d3ddev->Present(NULL,NULL,NULL,NULL); } // 닫기와 메모리 해제 close Direct3D and releases memory void cleanD3D(void) { // close and release the 3D device returned_d3ddev->Release(); // close and release Direct3D d3d->Release(); } // the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); hWnd = CreateWindowEx(NULL, L"WindowClass", L"첫번째 3D 프로그램", WS_OVERLAPPEDWINDOW, 300, 300, 800, 600, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // set up and initialize Direct3D initD3D(hWnd); // enter the main loop: MSG msg; while(TRUE) { while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message == WM_QUIT) break; render_frame(); } // clean up DirectX and COM cleanD3D(); return msg.wParam; } // this is the main message handler for the program LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc (hWnd, message, wParam, lParam); }
'온라인게임 > vc++' 카테고리의 다른 글
표준 c++ / C++ 시작 1 (0) | 2010.10.02 |
---|---|
게임 서버 (0) | 2010.10.02 |
vs 2010 (vc++ 10) (0) | 2010.10.01 |
온라인 게임 서버 (0) | 2010.10.01 |
알고리즘 bresenham (0) | 2010.09.16 |