Created
November 24, 2009 23:32
-
-
Save dejw/242334 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <d3dx9.h> | |
| #pragma comment (lib, "d3d9.lib") | |
| #pragma comment (lib, "d3dx9.lib") | |
| HWND hWnd; | |
| void init_window(int width = 800, int height = 600, const char* window_name = "SomeWindow"){ | |
| HINSTANCE hProg = GetModuleHandle(0); | |
| WNDCLASS wc; | |
| wc.cbClsExtra = 0; | |
| wc.cbWndExtra = 0; | |
| wc.hInstance = hProg; | |
| wc.lpfnWndProc = DefWindowProc; | |
| wc.lpszClassName = "WndClass"; | |
| wc.lpszMenuName = 0; | |
| wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); | |
| wc.hIcon = LoadIcon(hProg, IDI_WINLOGO); | |
| wc.style = CS_HREDRAW | CS_VREDRAW; | |
| wc.hCursor = LoadCursor(hProg, IDC_ARROW); | |
| RegisterClass(&wc); | |
| hWnd = CreateWindowEx(0, "WndClass", window_name, WS_OVERLAPPEDWINDOW, | |
| 0, 0, width, height, 0, 0, hProg, 0); | |
| ShowWindow(hWnd, 5); | |
| } | |
| int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int){ | |
| init_window(); | |
| IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION); | |
| IDirect3DDevice9* pDev; | |
| D3DPRESENT_PARAMETERS d3dpp; | |
| ZeroMemory(&d3dpp, sizeof(d3dpp)); | |
| d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; | |
| d3dpp.Windowed = true; | |
| d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; | |
| pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, | |
| D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDev); | |
| MSG msg; | |
| while(true) { | |
| if(PeekMessage(&msg, 0, 0U, 0U, PM_REMOVE)) { | |
| if(msg.message == WM_DESTROY) break; | |
| TranslateMessage(&msg); | |
| DispatchMessage(&msg); | |
| } else { | |
| pDev->Clear(0, 0, D3DCLEAR_TARGET, 0xff000000, 1, 0); | |
| pDev->BeginScene(); | |
| pDev->EndScene(); | |
| pDev->Present(0, 0, 0, 0); | |
| if (GetKeyState(VK_ESCAPE) & 0x0800) break; | |
| } | |
| } | |
| pDev->Release(); | |
| pD3D->Release(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment