简体   繁体   English

使用顶点缓冲对象渲染不同的三角形类型和三角形扇形? (OpenGL的)

[英]Rendering different triangle types and triangle fans using vertex buffer objects? (OpenGL)

About half of my meshes are using triangles, another half using triangle fans. 我大约一半的网格使用三角形,另一半使用三角形风扇。 I'd like to offload these into a vertex buffer object but I'm not quite sure how to do this. 我想将它们卸载到顶点缓冲区对象中,但是我不太确定如何做到这一点。 The triangle fans all have a different number of vertices... for example, one might have 5 and another 7. 三角形风扇的顶点总数都不同……例如,一个顶点可能具有5个顶点,而另一个顶点可能具有7个顶点。

VBO's are fairly straight forward using plain triangles, however I'm not sure how to use them with triangle fans or with different triangle types. VBO使用普通三角形相当简单,但是我不确定如何将它们与三角形风扇或不同三角形类型一起使用。 I'm fairly sure I need an index buffer, but I'm not quite sure what I need to do this. 我相当确定我需要索引缓冲区,但是我不太确定我需要做什么。

I know how many vertices make up each fan during run time... I'm thinking I can use that to call something like glArrayElement 我知道在运行时每个风扇有多少个顶点...我想我可以用它来调用诸如glArrayElement类的glArrayElement

Any help here would be much appreciated! 在这里的任何帮助将不胜感激!

VBOs and index buffers are an orthogonal things. VBO和索引缓冲区是正交的东西。 If you're not using index buffers yet, maybe it is wiser to move one step at a time. 如果您还没有使用索引缓冲区,那么一次移动一步可能是更明智的选择。

So... regarding your question. 所以...关于您的问题。 If you put all your triangle fans in a vbo, the only thing you need to draw them is to setup your vbo and pass the index in it for your fan start 如果将所有三角形风扇都放置在VBO中,则只需绘制它们即可设置VBO并在其中传递索引以启动风扇

   glBindBuffer(GL_VERTEX_BUFFER, buffer);
   glVertexPointer(3, GL_FLOAT, 0, NULL); // 3 floats per vertex
   for each i in fans
       glDrawArrays(GL_TRIANGLE_FAN, indef_of_first_vertex_for_fan[i], fan_vertex_count[i])

Edit : I'd have to say that you're probably better off transforming your fans to a regular triangle set, and use glDrawArrays(GL_TRIANGLES) for all your triangles. 编辑 :我不得不说,您可能最好将风扇转换为规则的三角形集,并对所有三角形使用glDrawArrays(GL_TRIANGLES) A call per primitive is rarely efficient. 每个原语的调用很少有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM