在OpenGL中绘制许多球体

发布于 2024-08-17 03:52:13 字数 351 浏览 2 评论 0原文

我想使用 OpenGL 绘制许多球体(~100k)。到目前为止,我正在做类似

for (int i=0; i<pnum; i++){
     glPushMatrix();
     glTranslatef(bpos[i].x, bpos[i].y, bpos[i].z);
     glCallList(DListSPHERE);
     glPopMatrix();
}

在使用适当的球体之前,我使用GL_POINTS。这使我能够使用包含所有点的数组调用 glDrawArrays ,这是非常高效的。有没有比上面的代码更好的方法来绘制许多相同的对象?

I want to draw many spheres (~100k) using OpenGL. So far, I'm doing something like

for (int i=0; i<pnum; i++){
     glPushMatrix();
     glTranslatef(bpos[i].x, bpos[i].y, bpos[i].z);
     glCallList(DListSPHERE);
     glPopMatrix();
}

Before using proper spheres, I used GL_POINTS. That allowed me to call glDrawArrays with an array containing all points which was very efficient. Is there a better way than the above code to draw many, identical objects?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没有心的人 2024-08-24 03:52:13

看看 instancing 上的此页面:它包含许多参考资料:

另请参阅维基百科上的几何实例

Have a look at this page on instancing: it contains many references:

See also Geometry instancing on Wikipedia.

心病无药医 2024-08-24 03:52:13

如果您绘制约 100k 球体,您可能需要考虑对它们进行光线投射,而不是使用多边形网格来近似它们。论文基于 GPU 的二次射线投射表面,Sigg 等人。 (2006) 和用Gumhold (2003) 的深度校正展示了如何做到这一点。如果这样做,您可以重用大部分快点精灵代码。

If you draw ~100k spheres, you might want to consider raycasting them instead of using polygon meshes to approximate them. The papers GPU-Based Ray-Casting of Quadratic Surfaces by Sigg et al. (2006) and Splatting Illuminated Ellipsoids with Depth Correction by Gumhold (2003) show how to do this. If you do this, you can reuse much of your fast point sprite code.

请持续率性 2024-08-24 03:52:13

您可以使用点精灵和片段着色器来复制渲染球体的效果,而无需实际的球体几何形状。不过,我会先尝试实例化。

You could use point sprites and a fragment shader to duplicate the effect of a rendered sphere without the actual sphere geometry. I would try instancing first, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文