如何将元素映射到 OpenGL VBO 中的颜色?
我正在使用 VBO 创建一个应用程序来渲染一些具有困难颜色结构的对象。我注意到,VBO 定义的元素颜色等于元素缓冲区中最后一个顶点索引。例如,当我使用像这样的点数组
double pointBuf[]={ -0.1d, 0.1d, 0,
0.1d, 0.1d, 0,
0.1d, -0.1d, 0};
color array:
double colorBuf[] = { 0d, 1d, 0d,
0d, 1d, 0d,
1d, 0d, 0d};
和 element array:
int elementBuf[] = {0, 1, 2};
来绘制一个三角形时,它将是红色的(因为 elementBuf 中的最后一个元素是 2,在 colorBuf 中它匹配红色)。
事实上,它可能会导致使用额外的内存来正确绘制所有内容。
还有其他可能的方式将颜色与元素联系起来吗?
I'm creating an app using VBO to render some objects with difficult color structure. I noticed, that VBO defines the color of the element equal to last vertex index in the element buffer. For example, when I use point array like this
double pointBuf[]={ -0.1d, 0.1d, 0,
0.1d, 0.1d, 0,
0.1d, -0.1d, 0};
color array:
double colorBuf[] = { 0d, 1d, 0d,
0d, 1d, 0d,
1d, 0d, 0d};
and element array:
int elementBuf[] = {0, 1, 2};
to draw a triangle, it will be red (as the last element in elementBuf is 2, in colorBuf it matches red).
In fact it can lead to additional memory usage to paint everything correctly.
Is there any other possible way to link colors with elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将着色模型设置为平滑,它将插入颜色。
glShadeModel(GL_SMOOTH);
或者你到底想实现什么?缓冲区中的三角形只有一种颜色?这是行不通的,你必须为每个顶点指定一种颜色......
if you set the Shademodel to smooth, it will interpolate the colors.
glShadeModel(GL_SMOOTH);
or what do you exactly want to achieve? only one color for the triangle in the buffer? that doesn't work, you have to specify a color for each vertex...
您需要了解的一件事是,顶点不仅仅是它的位置。顶点(用 OpenGL 术语来说)是属性的整个向量,
如果更改其中任何一个,您最终会得到一个完全不同的顶点。 OpenGL 数据模型的设计方式无法将每个属性放入自己的数组中并使用索引向量对它们进行寻址。而且这种数据模型会给实现高效缓存带来很大困难,从而严重降低性能。
你还告诉你内存不足。大多数现代系统为您提供数 GB 的图形客户端(即 CPU)内存和至少数百兆字节的图形服务器(即 GPU)内存。可以放入 GPU 内存的几何数据(即顶点)数量超出了 GPU 的实时处理能力;而且,这将远远多于屏幕上可用的像素。所以我确信你不太可能遇到任何内存问题,你的瓶颈将是另一个。
One thing you need to understand is, that a vertex is not just its position. A vertex (in OpenGL terms) is the whole vector of attributes
If you change any of these you end up with a completely different vertex. OpenGL's data model has not been designed in a way that it were possible to place each of the attributes in a own array and address them with index vectors. Also this kind of data model would cause major difficulties in implement efficient caching, so would seriously degrade performance.
Also you tell you're running out of memory. Most modern systems offer you several gigabytes of graphics client (i.e. CPU) memory and at least a few hundred megabytes of graphics server (i.e. GPU) memory. The amount of geometry data (i.e. vertices) you can put into GPU memory exceeds the realtime processing capabilities of GPUs; also that would be far more vertices than pixels available on your screen. So I'm positive that you're unlikely to run into any memory problems, your bottleneck will be/is another one.