且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

让颜色使用顶点缓冲对象在OpenGL元

更新时间:2023-11-08 09:59:10

一做的方法是使用一个彩色阵列。你可以通过调用 glColorPointer()做到这一点code> 作为你做 glVertexPointer()

One way to do it is to use a color array. You can do this by calling glColorPointer() in the same way as you do for glVertexPointer().

另外,我不知道这只是一个错字,或者如果你确实有这个错误,但你写的:

Also, I don't know if this is just a typo, or if you actually have this error, but you wrote:

glBufferData( GL_ARRAY_BUFFER, sizeof(vertex)+sizeof(colours), NULL,GL_STATIC_DRAW);

不过,你的顶点数组被命名为顶点而不是顶点(至少根据你刚才的发言)。如果它编译OK,那么它可能意味着你有一个名为顶点另一个变量或数据结构,但它不是做你的想法。

However, your vertex array is named "vertices" not "vertex" (at least according to your earlier statement). If it compiles OK, then it probably means you have another variable or data structure named vertex, but it's not doing what you think.

此外,由于你的数据不是交错(你有独立的顶点和颜色数据),我想你会想使用独立的缓冲区他们。如果他们在一个结构,你可以使用一个单一的阵列,并设置适当的步伐,但由于他们都没有交错的,我不知道,如果你试图做会工作的。

And since your data isn't interleaved (you have separate vertex and color data), I think you'll want to use separate buffers for them. If they were in one structure, you could use a single array, and set the stride appropriately, but since they aren't interleaved, I'm not sure if what you're attempting to do will work.