I am trying to render a cube in c++ using DirectX 11. I managed to render it, however I am not able to transform the model to the world position with perspective projection. I followed the MSDN tutorial for this
Here's the code :
{
DirectX::XMMATRIX g_World;
DirectX::XMMATRIX g_View;
DirectX::XMMATRIX g_Projection;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(ConstantBuffer);
bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = 0;
Device->CreateBuffer(&bd, NULL, &pConstantBuffer);
g_World = DirectX::XMMatrixIdentity();
DirectX::XMVECTOR Eye = DirectX::XMVectorSet(0.0f, 1.0f, -5.0f, 0.0f);
DirectX::XMVECTOR At = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
DirectX::XMVECTOR Up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
g_View = DirectX::XMMatrixLookAtLH(Eye, At, Up);
g_Projection = DirectX::XMMatrixPerspectiveFovLH(1.570796327f, winWidth / (FLOAT)winHeight, 0.01f, 100.0f);
ConstantBuffer cb;
cb.mWorld = XMMatrixTranspose(g_World);
cb.mView = XMMatrixTranspose(g_View);
cb.mProjection = XMMatrixTranspose(g_Projection);
DeviceContext->UpdateSubresource(pConstantBuffer, 0, NULL, &cb, 0, 0);
}
and here's the HLSL shader code :
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
float4 VShader(float4 position : POSITION) : SV_POSITION
{
position = mul(position, World);
position = mul(position, View);
position = mul(position, Projection);
return position;
}
float4 PShader(float4 position : SV_POSITION) : SV_TARGET
{
return float4(1.f, 0.f, 0.f, 1.f);
}
What I have tried:
all the matrices that are fed to the shader are calculated correctly, as it seems, but I'm not quite sure about the shader.