最近、DirectX9にて画像を表示するところまで来ました。
#しかし画像を表示すると、拡大して表示されます。
コードとしては、
#include<windows.h> #include<d3d9.h> #include<d3dx9.h> #pragma comment( lib, "d3d9.lib" ) #pragma comment( lib, "d3dx9d.lib" ) #pragma comment( lib, "d3dx9.lib" ) #pragma comment( lib, "dxerr.lib" ) LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_ERASEBKGND: return E_FAIL; } return DefWindowProc(hwnd, msg, wp, lp); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) { //構造体 HWND hwnd; MSG msg; WNDCLASS winc; LPDIRECT3D9 m_pD3D = NULL; D3DPRESENT_PARAMETERS m_D3DPP; D3DDISPLAYMODE d3ddm; LPDIRECT3DDEVICE9 m_pD3DDevice = NULL; LPDIRECT3DTEXTURE9 g_pTexture = NULL; LPD3DXSPRITE g_pSprite = NULL; RECT rc; D3DXVECTOR3 center, position; //DirectX初期化設定 d3ddm.Width = 1280; d3ddm.Height = 720; d3ddm.Format = D3DFMT_A8R8G8B8; d3ddm.RefreshRate = 60; winc.style = CS_HREDRAW | CS_VREDRAW; winc.lpfnWndProc = WndProc; winc.cbClsExtra = winc.cbWndExtra = 0; winc.hInstance = hInstance; winc.hIcon = LoadIcon(NULL, IDI_APPLICATION); winc.hCursor = LoadCursor(NULL, IDC_ARROW); winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winc.lpszMenuName = NULL; winc.lpszClassName = TEXT("WCN"); if (!RegisterClass(&winc)) return 0; hwnd = CreateWindow( TEXT("WCN"), TEXT("TEST"), WS_OVERLAPPEDWINDOW, 175, 50, 1280, 720, NULL, NULL, hInstance, NULL ); if (hwnd == NULL) return 0; BOOL isFullScreen = FALSE; for (int i = 0; i < __argc; i++) { if (_stricmp(__argv[i], "/f") == 0) { isFullScreen = TRUE; break; } } if ((m_pD3D = ::Direct3DCreate9(D3D_SDK_VERSION)) == 0) { return E_FAIL; } ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS)); m_D3DPP.BackBufferCount = 1; if (isFullScreen) { m_D3DPP.Windowed = FALSE; m_D3DPP.BackBufferWidth = 1280; m_D3DPP.BackBufferHeight = 720; } else { m_D3DPP.Windowed = TRUE; } m_D3DPP.BackBufferFormat = d3ddm.Format; m_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; m_D3DPP.EnableAutoDepthStencil = TRUE; m_D3DPP.AutoDepthStencilFormat = D3DFMT_D16; if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_D3DPP, &m_pD3DDevice))) { if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_D3DPP, &m_pD3DDevice))) { if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_D3DPP, &m_pD3DDevice))) { return E_FAIL; } } } //テクスチャの読み込み D3DXCreateTextureFromFile( m_pD3DDevice, TEXT("BG01.png"), &g_pTexture ); D3DXCreateSprite(m_pD3DDevice, &g_pSprite); //繰り返し処理 while (GetMessage(&msg, NULL, 0, 0)) { DispatchMessage(&msg); if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); continue; } m_pD3DDevice->BeginScene(); // ここに描画コード m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); g_pSprite->Begin(0); g_pSprite->Draw(g_pTexture, &rc, ¢er, &position, 0xFFFFFFFF); g_pSprite->End(); m_pD3DDevice->EndScene(); m_pD3DDevice->Present(NULL, NULL, NULL, NULL); if (FAILED(m_pD3DDevice->BeginScene())) { return 0; } if (FAILED(m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0))) { return 0; } g_pSprite->Begin(NULL); rc.left = 0; rc.top = 0; rc.right = 1280; rc.bottom = 720; center.x = 0; center.y = 0; position.x = 0; position.y = 0; g_pSprite->Draw(g_pTexture, &rc, ¢er, &position, 0xFFFFFFFF); g_pSprite->End(); m_pD3DDevice->EndScene(); if (FAILED(m_pD3DDevice->Present(0, 0, 0, 0))) { m_pD3DDevice->Reset(&m_D3DPP); } ShowWindow(hwnd, nCmdShow); } g_pTexture->Release(); g_pSprite->Release(); return msg.wParam; }
です
画像サイズは1280x720で、
ウィンドウサイズもそれと同じ1280x720です。
あなたの回答
tips
プレビュー