現在初期化が終わって黒い画面が表示されるようになったので、四角形(三角形二つ)を描画しようと思い
次のコードを実行しました。
DirectX9
1#include<windows.h> 2#include<d3d9.h> 3#include<d3dx9.h> 4#pragma comment( lib, "d3d9.lib" ) 5#pragma comment( lib, "d3dx9d.lib" ) 6#pragma comment( lib, "d3dx9.lib" ) 7#pragma comment( lib, "dxerr.lib" ) 8#define MY_VERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE) 9 10LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { 11 switch (msg) { 12 case WM_DESTROY: 13 PostQuitMessage(0); 14 return 0; 15 } 16 return DefWindowProc(hwnd, msg, wp, lp); 17} 18 19struct MY_VERTEX { 20 D3DXVECTOR3 p; 21 DWORD color; 22 23}; 24 25int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 26 PSTR lpCmdLine, int nCmdShow) { 27 HWND hwnd; 28 MSG msg; 29 WNDCLASS winc; 30 LPDIRECT3D9 m_pD3D = NULL; 31 D3DPRESENT_PARAMETERS m_D3DPP; 32 D3DDISPLAYMODE d3ddm; 33 LPDIRECT3DDEVICE9 m_pD3DDevice = NULL; 34 LPDIRECT3DVERTEXBUFFER9 m_pMyVB; 35 36 37 d3ddm.Width = 1280; 38 d3ddm.Height = 720; 39 d3ddm.Format = D3DFMT_A8R8G8B8; 40 d3ddm.RefreshRate = 60; 41 winc.style = CS_HREDRAW | CS_VREDRAW; 42 winc.lpfnWndProc = WndProc; 43 winc.cbClsExtra = winc.cbWndExtra = 0; 44 winc.hInstance = hInstance; 45 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 46 winc.hCursor = LoadCursor(NULL, IDC_ARROW); 47 winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 48 winc.lpszMenuName = NULL; 49 winc.lpszClassName = TEXT("WCN"); 50 51 if (!RegisterClass(&winc)) return 0; 52 53 hwnd = CreateWindow( 54 TEXT("WCN"), TEXT("東方幻想郷絶滅化計画~Destroy The World~"), 55 WS_OVERLAPPEDWINDOW, 56 175, 50, 1280, 720, NULL, NULL, 57 hInstance, NULL 58 ); 59 60 if (hwnd == NULL) return 0; 61 BOOL isFullScreen = FALSE; 62 for (int i = 0; i < __argc; i++) { 63 if (_stricmp(__argv[i], "/f") == 0) { 64 isFullScreen = TRUE; 65 break; 66 } 67 } 68 69 70 if ((m_pD3D = ::Direct3DCreate9(D3D_SDK_VERSION)) == 0) { 71 return E_FAIL; 72 } 73 74 ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS)); 75 76 m_D3DPP.BackBufferCount = 1; 77 if (isFullScreen) { 78 m_D3DPP.Windowed = FALSE; 79 m_D3DPP.BackBufferWidth = 1280; 80 m_D3DPP.BackBufferHeight = 720; 81 } 82 else { 83 m_D3DPP.Windowed = TRUE; 84 } 85 m_D3DPP.BackBufferFormat = d3ddm.Format; 86 m_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; 87 m_D3DPP.EnableAutoDepthStencil = TRUE; 88 m_D3DPP.AutoDepthStencilFormat = D3DFMT_D16; 89 90 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 91 D3DDEVTYPE_HAL, 92 hwnd, 93 D3DCREATE_HARDWARE_VERTEXPROCESSING, 94 &m_D3DPP, &m_pD3DDevice))) { 95 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 96 D3DDEVTYPE_HAL, 97 hwnd, 98 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 99 &m_D3DPP, &m_pD3DDevice))) { 100 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 101 D3DDEVTYPE_REF, 102 hwnd, 103 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 104 &m_D3DPP, &m_pD3DDevice))) { 105 return E_FAIL; 106 } 107 } 108 } 109 110 if (FAILED(m_pD3DDevice->BeginScene())) { 111 112 if (FAILED(m_pD3DDevice->CreateVertexBuffer( 113 4 * sizeof(MY_VERTEX), 114 D3DUSAGE_WRITEONLY, 115 MY_VERTEX_FVF, 116 D3DPOOL_MANAGED, 117 &m_pMyVB, 118 NULL))) { 119 return E_FAIL; 120 MY_VERTEX* v; 121 m_pMyVB->Lock(0, 0, (void**)&v, 0); 122 123 v[0].p = D3DXVECTOR3(-1.5f, 1.5f, 0.0f); //頂点1 124 v[0].p = D3DXVECTOR3(1.5f, 1.5f, 0.0f); //頂点2 125 v[0].p = D3DXVECTOR3(-1.5f, -1.5f, 0.0f); //頂点3 126 v[0].p = D3DXVECTOR3(1.5f, -1.5f, 0.0f); //頂点4 127 128 //頂点データ:頂点の基本的な色の設定(すべて白色) 129 v[0].color = v[1].color = v[2].color = v[3].color 130 = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); 131 132 m_pMyVB->Unlock(); 133 m_pD3DDevice->SetStreamSource(0, m_pMyVB, 0, sizeof(MY_VERTEX)); 134 135 m_pD3DDevice->SetFVF(MY_VERTEX_FVF); 136 m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); 137 } 138 139 return 0; 140 } 141 142 if (FAILED(m_pD3DDevice->Clear(0, NULL, 143 D3DCLEAR_TARGET | 144 D3DCLEAR_ZBUFFER, 145 D3DCOLOR_XRGB(0, 0, 0), 146 1.0f, 147 0))) { 148 return 0; 149 } 150 151 m_pD3DDevice->EndScene(); 152 153 ShowWindow(hwnd, nCmdShow); 154 if (FAILED(m_pD3DDevice->Present(0, 0, 0, 0))) { 155 m_pD3DDevice->Reset(&m_D3DPP); 156 } 157 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg); 158 return msg.wParam; 159}
四角形は表示されず、黒い画面だけ表示されました。
なぜでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。