I tried to create this 2D triangle in with the Input Assembler set to triangle strip:
1.(0.0f, 0.0f, 0.5f)
2.(-0.5f, 0.0f, 0.5f)
3.(-0.5f, -0.5f, 0.5f)
However, no triangle was drawn, in fact nothing was drawn on the render target, not even a single line. I messed around, and then I swapped coordinates 2
and 3
, and it worked. The triangle was drawn just as I intended it to be. What is the reason for this odd behaviour?
You define your vertex in counter-clockwise order, and Direct3D will cull faces define in counter-clockwise order by default, so your triangle was culled during back-face culling, thus you got nothing rendered.
You should consider two things when you drawing a triangle in DirectX.
The order how you defined your vertices determines the front face and the back face. A front face is one in which vertices are defined in clockwise order, try to define your vertex in clockwise order.
Front face and vertex normals
The culling mode specifies how back-facing triangles are culled, try using D3D11_CULL_NONE to test your code, this will make sure every triangle will be render regardless the definition order of the vertices.
Culling state
cull mode for DirectX11
You should take care when drawing triangle strips, since the backface-culling flag is automatically flipped on even-numbered triangles. consider the following picture. for the first triangle v1v2v3, the culling mode is counterclock-wise, it will be rendered, for the second triangle v2v3v4, the culling mode flipped to clockwise, it will be rendered too. and for the third triangle, the culling mode change back again, and so on. if you want to render such a triange strip, you should define the vertices in this order: v1, v2, v3, v4, ... vn.
Triangle Strips