Reputation: 1
I have been trying to make it so that 2 triangles are displayed however the program only reads the coordinates for the first triangle and so only the first one is displayed. I have no idea what the problem is. Please help
static const Vertex s_vertexData[]
{
XMFLOAT3{ 0.0f, 0.5f, 0.5f },
XMFLOAT3{ 0.5f, -0.5f, 0.5f },
XMFLOAT3{ -0.5f, -0.5f, 0.5f },
XMFLOAT3{ 1.0f, 0.5f, 0.5f },
XMFLOAT3{ 1.5f, -0.5f, 0.5f },
XMFLOAT3{ 0.6f, -0.5f, 0.5f }
};
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( s_vertexData);
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
InitData.pSysMem = s_vertexData;
hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
if( FAILED( hr ) )
return hr;
// Set vertex buffer
UINT stride = sizeof( Vertex);
UINT offset = 0;
g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );
// Set primitive topology
g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Upvotes: 0
Views: 570
Reputation: 41127
The most likely cause of the issue is the culling mode in combination with your triangle winding. See Wikipedia
In DirectX 11, this is controlled by the rasterizer state which you have not set in this code. The default state without setting it is CullMode
set to D3D11_CULL_BACK
and FrontCounterClockwise
set to FALSE
.
Try creating and setting a Rasterizer State object that sets cull-mode to "None".
ID3D11RasterizerState* g_pRasterState = nullptr;
...
CD3D11_RASTERIZER_DESC rasterDesc(D3D11_FILL_SOLID, D3D11_CULL_NONE,
FALSE /* FrontCounterClockwise */,
D3D11_DEFAULT_DEPTH_BIAS,
D3D11_DEFAULT_DEPTH_BIAS_CLAMP,
D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS,
TRUE /* DepthClipEnable */,
FALSE /* ScissorEnable */,
TRUE /* MultisampleEnable */,
FALSE /* AntialiasedLineEnable */);
hr = g_pd3dDevice->CreateRasterizerState( &rasterDesc, &g_pRasterState );
if( FAILED( hr ) )
return hr;
...
g_pImmediateContext->RSSetState( g_pRasterState );
As you are new to DirectX 11, you should take a look at the DirectX Tool Kit tutorials.
Upvotes: 1