Odd behaviour when trying to create triangle using TriangleStrip Topologu

∥☆過路亽.° 提交于 2019-12-11 11:01:49

问题


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?


回答1:


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.

  1. The order you defined your vertices.
  2. The culling mode currently used.

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



来源:https://stackoverflow.com/questions/13296440/odd-behaviour-when-trying-to-create-triangle-using-trianglestrip-topologu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!