現在、DirectX9の初期化コードを書いたあたりです。
コードは以下の通りです。
DriectX9
1#include<windows.h> 2#include<d3d9.h> 3#pragma comment( lib, "d3d9.lib" ) 4#pragma comment( lib, "d3dx9d.lib" ) 5#pragma comment( lib, "d3dx9.lib" ) 6#pragma comment( lib, "dxerr.lib" ) 7 8LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { 9 switch (msg) { 10 case WM_DESTROY: 11 PostQuitMessage(0); 12 return 0; 13 } 14 return DefWindowProc(hwnd, msg, wp, lp); 15} 16 17int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 18 PSTR lpCmdLine, int nCmdShow) { 19 HWND hwnd; 20 MSG msg; 21 WNDCLASS winc; 22 LPDIRECT3D9 m_pD3D = NULL; 23 D3DPRESENT_PARAMETERS m_D3DPP; 24 D3DDISPLAYMODE d3ddm; 25 LPDIRECT3DDEVICE9 m_pD3DDevice = NULL; 26 27 d3ddm.Width = 1280; 28 d3ddm.Height = 720; 29 d3ddm.Format = D3DFMT_A8R8G8B8; 30 d3ddm.RefreshRate = 60; 31 winc.style = CS_HREDRAW | CS_VREDRAW; 32 winc.lpfnWndProc = WndProc; 33 winc.cbClsExtra = winc.cbWndExtra = 0; 34 winc.hInstance = hInstance; 35 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 36 winc.hCursor = LoadCursor(NULL, IDC_ARROW); 37 winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 38 winc.lpszMenuName = NULL; 39 winc.lpszClassName = TEXT("WCN"); 40 41 if (!RegisterClass(&winc)) return 0; 42 43 hwnd = CreateWindow( 44 TEXT("WCN"), TEXT("TEST"), 45 WS_OVERLAPPEDWINDOW, 46 175, 50, 1280, 720, NULL, NULL, 47 hInstance, NULL 48 ); 49 50 if (hwnd == NULL) return 0; 51 BOOL isFullScreen = FALSE; 52 for (int i = 0; i < __argc; i++) { 53 if (_stricmp(__argv[i], "/f") == 0) { 54 isFullScreen = TRUE; 55 break; 56 } 57 } 58 59 60 if ((m_pD3D = ::Direct3DCreate9(D3D_SDK_VERSION)) == 0) { 61 return E_FAIL; 62 } 63 64 ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS)); 65 66 m_D3DPP.BackBufferCount = 1; 67 if (isFullScreen) { 68 m_D3DPP.Windowed = FALSE; 69 m_D3DPP.BackBufferWidth = 1280; 70 m_D3DPP.BackBufferHeight = 720; 71 } 72 else { 73 m_D3DPP.Windowed = TRUE; 74 } 75 m_D3DPP.BackBufferFormat = d3ddm.Format; 76 m_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; 77 m_D3DPP.EnableAutoDepthStencil = TRUE; 78 m_D3DPP.AutoDepthStencilFormat = D3DFMT_D16; 79 80 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 81 D3DDEVTYPE_HAL, 82 hwnd, 83 D3DCREATE_HARDWARE_VERTEXPROCESSING, 84 &m_D3DPP, &m_pD3DDevice))) { 85 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 86 D3DDEVTYPE_HAL, 87 hwnd, 88 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 89 &m_D3DPP, &m_pD3DDevice))) { 90 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 91 D3DDEVTYPE_REF, 92 hwnd, 93 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 94 &m_D3DPP, &m_pD3DDevice))) { 95 return E_FAIL; 96 } 97 } 98 } 99 100 if (FAILED(m_pD3DDevice->Clear(0, NULL, 101 D3DCLEAR_TARGET | 102 D3DCLEAR_ZBUFFER, 103 D3DCOLOR_XRGB(0, 0, 0), 104 1.0f, 105 0))) { 106 return 0; 107 } 108 109 if (FAILED(m_pD3DDevice->BeginScene())) { 110 m_pD3DDevice->EndScene(); 111 } 112 113 if (FAILED(m_pD3DDevice->Present(0, 0, 0, 0))) { 114 m_pD3DDevice->Reset(&m_D3DPP); 115 } 116 ShowWindow(hwnd, nCmdShow); 117 118 119 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg); 120 return msg.wParam; 121}
実行するとエラーは出ませんが、白いウィンドウのままで黒くなりません。
一応、RGBは0,0,0になっているので黒く表示されるはずなんですけどね?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/07 16:23
2020/05/07 16:29 編集
2020/05/07 16:38