Hello,
I'm still trying to get something on my screen except a blue rectangle,
(I guess it is the 5th time I make this project :( )
But nothing is drawn. I can't explain why - I have very little experience with Direct3D.
I'm not even sure my shaders get called.
Here's my render function:
float color[] = {0.0f,0.25f,0.5f,1.0f};
_devcon->ClearRenderTargetView(_target, color);
//Do rendering stuff here
//Set the primitive Topology
_devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
//Set index & vertex buffers
_devcon->IASetIndexBuffer(_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
UINT stride = sizeof(Vertex), offset = 0;
_devcon->IASetVertexBuffers(0, 1, &_vertexBuffer, &stride, &offset);
//Activate the shaders
_devcon->IASetInputLayout(_inputLayout);
_devcon->VSSetShader(_vertexShader, 0, 0);
_devcon->PSSetShader(_pixelShader, 0, 0);
//Set the constant buffers
ID3D11Buffer *matrixBuf;
D3D11_BUFFER_DESC cbd;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.ByteWidth = sizeof(MatrixBuffer);
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0;
cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.StructureByteStride = 0;
MatrixBuffer m;
m.world = XMMatrixIdentity();
m.view = XMMatrixLookAtLH(XMLoadFloat3(new XMFLOAT3(0.0f,0.0f,-5.0f)),
XMLoadFloat3(new XMFLOAT3(0.0f,0.0f,0.0f)),
XMLoadFloat3(new XMFLOAT3(0.0f,1.0f,0.0f)));
m.projection = XMMatrixPerspectiveFovLH(XM_PIDIV4, 1.777f, 0.01f, 10000.0f);
D3D11_SUBRESOURCE_DATA matrixData;
matrixData.pSysMem = &m;
matrixData.SysMemPitch = 0;
matrixData.SysMemSlicePitch = 0;
HRESULT hRes = _dev->CreateBuffer(&cbd, &matrixData, &matrixBuf);
if (FAILED(hRes))
return false;
_devcon->VSSetConstantBuffers(0, 1, &matrixBuf);
_devcon->DrawIndexed(18, 0, 0);
_swapchain->Present(0,0);
return true;
Btw. The structure MatrixBuffer is something like:
struct MatrixBuffer
{
XMMATRIX world;
XMMATRIX view;
XMMATRIX projection;
};
And here's my vertex shader:
cbuffer cbPerObject
{
float4x4 world;
float4x4 view;
float4x4 projection;
};
struct VertexIn
{
float3 pos : POSITION;
float4 col : COLOR;
};
struct VertexOut
{
float4 pos : SV_POSITION;
float4 col : COLOR;
};
VertexOut main (VertexIn input)
{
VertexOut vout;
vout.pos = float4 (input.pos, 1.0f);
vout.pos = mul(vout.pos, world);
vout.pos = mul(vout.pos, view);
vout.pos = mul(vout.pos, projection);
vout.col = input.col;
return vout;
}
The shaders compile (hopefully) properly. (The result from D3DXCompileFromFile is S_OK!)