Nanashi-softプログラマ専用DirectX11開発


◇DirectX11プログラミング -2つ表示するにはどうするの?-

ふと,疑問に思いました
2つの板ポリを表示するにはどうすればいいのか?

ただ普通に,頂点を座標を送ると,全部くっついて1つの物体とみなされるでしょう
それに,シェーダーって1つのプログラムなのに,それぞれの物体に別のテクスチャー貼るとかできるの?

単純に考えてやってみた
ワールド変換を違う座標で2回やれば,同じ物体を2箇所に表示できないか?
わかっている人にはアフォなことやっとる。と思われるかも知れませんが(^^;

今のプログラムをメインループの中に持っていく
↓こんな感じww
	//メインループ
MSG hMsg;
while(true){
while(PeekMessageW(&hMsg, NULL, 0, 0, PM_REMOVE)){
if(hMsg.message == WM_QUIT){
goto End;
}
TranslateMessage(&hMsg);
DispatchMessage(&hMsg);
}

//背景クリア
float ClearColor[] = {0.0f, 0.0f, 1.0f, 1.0f};
hpDeviceContext->ClearRenderTargetView(hpRenderTargetView, ClearColor);

//ワールド変換用行列を生成
XMMATRIX hWorld; //ワールド変換行列
//初期化
hWorld = XMMatrixIdentity();

XMMATRIX hView; //ビュー変換行列
XMVECTOR hEye = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f); //カメラの位置
XMVECTOR hAt = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f); //焦点の位置
XMVECTOR hUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
hView = XMMatrixLookAtLH(hEye, hAt, hUp);

XMMATRIX hProjection; //透視射影変換行列
hProjection = XMMatrixPerspectiveFovLH(D3DXToRadian(45.0f), 16.0f/9.0f, 0.0f, 1000.0f);

//それらをシェーダーに送る
struct ConstantBuffer
{
XMMATRIX mWorld;
XMMATRIX mView;
XMMATRIX mProjection;
};
//constantバッファ生成
ID3D11Buffer* hpConstantBuffer = NULL;
hBufferDesc.ByteWidth = sizeof(ConstantBuffer);
hBufferDesc.Usage = D3D11_USAGE_DEFAULT;
hBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
hBufferDesc.CPUAccessFlags = 0;
hBufferDesc.MiscFlags = 0;
hBufferDesc.StructureByteStride = sizeof(float);
if(FAILED(hpDevice->CreateBuffer(&hBufferDesc, NULL, &hpConstantBuffer))){
MessageBoxW(hWnd, L"Create ConstantBuffer", L"Err", MB_ICONSTOP);
goto End;
}

//ID3D11DeviceContext* g_pImmediateContext = NULL;
ConstantBuffer hConstantBuffer;
hConstantBuffer.mWorld = XMMatrixTranspose(hWorld);
hConstantBuffer.mView = XMMatrixTranspose(hView);
hConstantBuffer.mProjection = XMMatrixTranspose(hProjection);
hpDeviceContext->UpdateSubresource(hpConstantBuffer, 0, NULL, &hConstantBuffer, 0, 0);

hpDeviceContext->VSSetConstantBuffers(0, 1, &hpConstantBuffer);

//描画
hpDeviceContext->Draw(TYOUTEN, 0);

hpDXGISwpChain->Present(0, 0);

}
これがまた,ちゃんと動くんだ(*'-')
気にせず,Presentの前に,ワールド変換と描画を書きます
		XMMATRIX hRotate;
hRotate = XMMatrixRotationZ(D3DXToRadian(-45.0f));
hWorld = XMMatrixMultiply(hWorld, hRotate);

hConstantBuffer.mWorld = XMMatrixTranspose(hWorld);
hpDeviceContext->UpdateSubresource(hpConstantBuffer, 0, NULL, &hConstantBuffer, 0, 0);
hpDeviceContext->VSSetConstantBuffers(0, 1, &hpConstantBuffer);

//描画
hpDeviceContext->Draw(TYOUTEN, 0);

hpDXGISwpChain->Present(0, 0);
2枚出てるww(冗談のつもりでした)



TOPプログラマ専用DirectX11開発

Melonbooks DL