DirectX9にて画像の表示が乱れます

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
MZK_0104
記事: 2
登録日時: 1週間前

DirectX9にて画像の表示が乱れます

#1

投稿記事 by MZK_0104 » 1週間前

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;
	}
	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;
	LPDIRECT3DTEXTURE9 g_pTexture02 = NULL;
	LPD3DXSPRITE g_pSprite = NULL;
	RECT rcMz;
	D3DXVECTOR3 centerMz, positionMz;
	RECT rcMw;
	D3DXVECTOR3 centerMw, positionMw;

	rcMz.left = 100;
	rcMz.top = 300;
	rcMz.right = 1920;
	rcMz.bottom = 1080;
	centerMz.x = 0;
	centerMz.y = 0;
	positionMz.x = 0;
	positionMz.y = 0;

	rcMw.left = 0;
	rcMw.top = 0;
	rcMw.right = 1280;
	rcMw.bottom = 720;
	centerMw.x = 0;
	centerMw.y = 0;
	positionMw.x = 0;
	positionMw.y = 0;

	ZeroMemory(&msg, sizeof(msg));
	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 | WS_VISIBLE,
		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("Mz01.png"), &g_pTexture02);
	D3DXCreateTextureFromFile(m_pD3DDevice, TEXT("BG.png"), &g_pTexture);

	D3DXCreateSprite(m_pD3DDevice, &g_pSprite);

	m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			continue;
		}

		m_pD3DDevice->BeginScene();

		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);

		// スプライトの描画処理
		g_pSprite->Draw(
			g_pTexture,
			&rcMw,
			&centerMw,
			&positionMw,
			0xFFFFFFFF
		);

		g_pSprite->Draw(
			g_pTexture02,
			&rcMz,
			&centerMz,
			&positionMz,
			0xFFFFFFFF
		);
		g_pSprite->End();

		m_pD3DDevice->EndScene();
		m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
	}

	g_pTexture->Release();
	g_pSprite->Release();
	return msg.wParam;
}
画像を二つ描画するソースコードです。
どなたかわかる方教えてください。

“C言語何でも質問掲示板” へ戻る