DirectX9で画像を描画するところまで来ました。
コードは以下の通りです。
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 9LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { 10 switch (msg) { 11 case WM_DESTROY: 12 PostQuitMessage(0); 13 return 0; 14 case WM_ERASEBKGND: 15 return E_FAIL; 16 } 17 return DefWindowProc(hwnd, msg, wp, lp); 18} 19 20int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 21 PSTR lpCmdLine, int nCmdShow) { 22 HWND hwnd; 23 MSG msg; 24 WNDCLASS winc; 25 LPDIRECT3D9 m_pD3D = NULL; 26 D3DPRESENT_PARAMETERS m_D3DPP; 27 D3DDISPLAYMODE d3ddm; 28 LPDIRECT3DDEVICE9 m_pD3DDevice = NULL; 29 LPDIRECT3DTEXTURE9 g_pTexture = NULL; 30 31 32 d3ddm.Width = 1280; 33 d3ddm.Height = 720; 34 d3ddm.Format = D3DFMT_A8R8G8B8; 35 d3ddm.RefreshRate = 60; 36 winc.style = CS_HREDRAW | CS_VREDRAW; 37 winc.lpfnWndProc = WndProc; 38 winc.cbClsExtra = winc.cbWndExtra = 0; 39 winc.hInstance = hInstance; 40 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 41 winc.hCursor = LoadCursor(NULL, IDC_ARROW); 42 winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 43 winc.lpszMenuName = NULL; 44 winc.lpszClassName = TEXT("WCN"); 45 46 if (!RegisterClass(&winc)) return 0; 47 48 hwnd = CreateWindow( 49 TEXT("WCN"), TEXT("幻想郷絶滅化計画~Destroy The World~"), 50 WS_OVERLAPPEDWINDOW, 51 175, 50, 1280, 720, NULL, NULL, 52 hInstance, NULL 53 ); 54 55 if (hwnd == NULL) return 0; 56 BOOL isFullScreen = FALSE; 57 for (int i = 0; i < __argc; i++) { 58 if (_stricmp(__argv[i], "/f") == 0) { 59 isFullScreen = TRUE; 60 break; 61 } 62 } 63 64 65 if ((m_pD3D = ::Direct3DCreate9(D3D_SDK_VERSION)) == 0) { 66 return E_FAIL; 67 } 68 69 ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS)); 70 71 m_D3DPP.BackBufferCount = 1; 72 if (isFullScreen) { 73 m_D3DPP.Windowed = FALSE; 74 m_D3DPP.BackBufferWidth = 1280; 75 m_D3DPP.BackBufferHeight = 720; 76 } 77 else { 78 m_D3DPP.Windowed = TRUE; 79 } 80 m_D3DPP.BackBufferFormat = d3ddm.Format; 81 m_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; 82 m_D3DPP.EnableAutoDepthStencil = TRUE; 83 m_D3DPP.AutoDepthStencilFormat = D3DFMT_D16; 84 85 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 86 D3DDEVTYPE_HAL, 87 hwnd, 88 D3DCREATE_HARDWARE_VERTEXPROCESSING, 89 &m_D3DPP, &m_pD3DDevice))) { 90 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 91 D3DDEVTYPE_HAL, 92 hwnd, 93 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 94 &m_D3DPP, &m_pD3DDevice))) { 95 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 96 D3DDEVTYPE_REF, 97 hwnd, 98 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 99 &m_D3DPP, &m_pD3DDevice))) { 100 return E_FAIL; 101 } 102 } 103 } 104 D3DXCreateTextureFromFile(m_pD3DDevice, "sample0003.bmp", &g_pTexture); 105 106 if (FAILED(m_pD3DDevice->BeginScene())) { 107 return 0; 108 } 109 110 if (FAILED(m_pD3DDevice->Clear(0, NULL, 111 D3DCLEAR_TARGET | 112 D3DCLEAR_ZBUFFER, 113 D3DCOLOR_XRGB(0, 0, 0), 114 1.0f, 115 0))) { 116 return 0; 117 } 118 119 m_pD3DDevice->EndScene(); 120 121 ShowWindow(hwnd, nCmdShow); 122 if (FAILED(m_pD3DDevice->Present(0, 0, 0, 0))) { 123 m_pD3DDevice->Reset(&m_D3DPP); 124 } 125 while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg); 126 return msg.wParam; 127}
D3DXCreateTextureFromFile(m_pD3DDevice, "sample0003.bmp", &g_pTexture);
で画像を読み込んでいるのですが、sample0003.bmpにエラーが出ます。
エラー内容は、
型"const char*"の引数はLPCWSTRのパラメターと互換性がありません。
だそうです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。