glInterleavedArray 格式
我有一个交错数组格式,我想在 open GL 中渲染它。它是一个三角形数组。顶点是 2D 浮点,颜色是 RGBA 浮点。也就是说,单个三角形的布局如下:
{vertex.x, vertex.y, color.red, color.blue, color.green, color.alpha, ...}
其中所有数字都是单精度浮点数。我无法弄清楚格式参数应该是什么。似乎需要V2F和C4F,但不存在这样的符号常量。我可以像 (GL_V2F | GL_C4F)
那样将它们组合在一起吗?
更新:我正在使用 python 和 pyopengl。 tibur 的答案非常明确,如果我用 C 编程,我就完成了。 python 代码非常相似,但我必须将颜色数组中的指针偏移 8 个字节。我不知道如何在 python 中执行此操作,或者是否可以完成:
strideInBytes = 24
interleavedBytes = array.tostring()
glVertexPointer(2, GL_FLOAT, 24, interleavedBytes)
glColorPointer(4, GL_FLOAT, 24, interleavedBytes) #The first color actually starts on the 9th byte
我需要避免复制整个交错数组。否则我可以复制一份并砍掉前 8 个字节。
I have an interleaved array format and I want to render it in open GL. It is an array of triangles. The vertices are 2D floating points and the colors are RGBA floating points. That is, a single triangle is layed out this this:
{vertex.x, vertex.y, color.red, color.blue, color.green, color.alpha, ...}
Where all number are single precision floats. I'm having trouble figuring out what the format parameter should be. It seems like it needs V2F and C4F, but not such symbolic constant exists. Can I OR them together like (GL_V2F | GL_C4F)
?
UPDATE: I'm using python and pyopengl. tibur's answer is very clear and if I were programming in C I'd be done. The python code is pretty similar, but I have to have to offset the pointer into the color array by 8 bytes. I don't know how to do this in python or if it even can be done:
strideInBytes = 24
interleavedBytes = array.tostring()
glVertexPointer(2, GL_FLOAT, 24, interleavedBytes)
glColorPointer(4, GL_FLOAT, 24, interleavedBytes) #The first color actually starts on the 9th byte
I need to avoid copying the entire interleaved array. Otherwise I could just make a copy and chop off the first 8 bytes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能对它们进行“或”运算。您需要使用以下代码:
No, you can't OR them. You need to use the following code: