如何使用“顶点缓冲对象"渲染许多不同的圆? [英] How do I use Vertex Buffer Objects to render many different circles?

查看:118
本文介绍了如何使用“顶点缓冲对象"渲染许多不同的圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个涉及许多圈子的游戏(好吧,三角形迷,但你明白了).每个圆将具有x位置,y位置和质量属性.每个圆的质量属性将有所不同.另外,我想给一些圆形的组上色,同时保持透明的圆心,并沿圆的周长逐渐褪色为不透明.

有人告诉我要使用VBO,并且整天都在使用Google搜索.我想要一个完整的示例,说明如何绘制这些圆圈,并给出有关VBO如何工作的说明,同时使说明保持简单.

解决方案

我自己还没有实现VBO,但是据我了解,它们的工作方式类似于纹理对象.实际上,当我提醒自己并向他人解释什么是VBO时,我喜欢错误地将纹理对象称为纹理缓冲对象",以增强概念上的相似性.

(不要与NVIDIA指定的扩展名缓冲区纹理混合使用 GL_EXT_texture_buffer_object .)

让我们想一想:什么是纹理对象?它们是您使用glGenTextures()生成的对象. glGenBuffersARB()做类似的事情.类比适用于glBindTexture()glBindBufferARB().

(从OpenGL 1.5开始,函数glGenBuffers()glBindBuffer()已进入核心OpenGL,因此您可以使用它们代替扩展名.)

但是这些纹理对象"到底是什么,它们做什么用?好吧,请考虑一下,实际上,您可以在每个帧中使用glTexture2D()来设置纹理.纹理对象仅用于减少GPU与主内存之间的流量.而不是发送整个像素阵列,您只发送已知为静态的纹理对象的"OpenGL名称" (即整数标识符).

VBO具有类似目的.不必一次又一次地发送顶点数组,而是使用glBufferData()上传一次数组,然后仅发送对象的"OpenGL名称".它们适用于静态对象,不适用于动态对象.实际上,许多通用3D引擎(例如Ogre3D)为您提供了一种指定网格是动态还是静态的方法,很可能是为了让您在VBO和顶点数组之间做出决定.

出于您的目的,VBO是的正确答案.您需要不断变形和变化的众多简单对象.简单来说,我指的是那些顶点少于200个的顶点.除非您打算编写一个非常智能且复杂的顶点着色器,否则VBO对您而言.您想使用顶点阵列,您可以轻松地从主CPU对其进行操作并在每帧更新它们,而无需对图形卡进行特殊调用以将整个VBO重新上传到图形卡上(这可能比发送顶点阵列要慢). /p>

这是来自nVidia的一个很好的letscallit手册页",它是关于VBO API的 .阅读以获取更多信息!

I'm trying to write a game that deals with many circles (well, Triangle Fans, but you get the idea). Each circle will have an x position, a y position, and a mass property. Every circle's mass property will be different. Also, I want to color some groups of circles different, while keeping a transparent circle center, and fading to opaque along the perimeter of the circles.

I was told to use VBOs, and have been Googling all day. I would like a full example on how I would draw these circles and an explanation as to how VBOs work, while keeping that explanation simple.

解决方案

I have not implemented VBOs myself yet, but from what I understand, they work similar to texture objects. In fact, when I am reminding myself and explaining to others what VBOs are, I like to incorrectly call texture objects 'texture buffer objects', to reinforce the conceptual similarity.

(Not to be mixed with buffer textures from NVIDIA-specified extension GL_EXT_texture_buffer_object.)

So let's think: what are texture objects? They are objects you generate using glGenTextures(). glGenBuffersARB() does similar thing. An analogy applies with glBindTexture() and glBindBufferARB().

(As of OpenGL 1.5, functions glGenBuffers() and glBindBuffer() have entered core OpenGL, so you can use them in place of the extension equivalents.)

But what exactly are these 'texture objects', and what do they do? Well, consider that you can, actually, use glTexture2D() in each frame to set up a texture. Texture objects only serve to reduce traffic between GPU and main memory; instead of sending entire pixel array, you send just the "OpenGL name" (that is, an integer identifier) of the texture object which you know to be static.

VBOs serve similar purpose. Instead of sending the vertex array over and over, you upload the array once using glBufferData() and then send just the "OpenGL name" of the object. They are great for static objects, and not so great for dynamic objects. In fact, many generic 3D engines such as Ogre3D provide you with a way to specify if a mesh is dynamic or static, quite probably in order to let you decide between VBOs and vertex arrays.

For your purposes, VBOs are not the right answer. You want numerous simple objects that are continuously morphing and changing. By simple, I mean those with less than 200 vertices. Unless you intend to write a very smart and complex vertex shader, VBOs are not for you. You want to use vertex arrays, which you can easily manipulate from main CPU and update them each frame without making special calls to graphics card to reupload the entire VBO onto the graphics card (which may turn out slower than just sending vertex arrays).

Here's a quite good letscallit "man page" from nVidia about VBO API. Read it for further info!

这篇关于如何使用“顶点缓冲对象"渲染许多不同的圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆