opengl vbo dma数组
我正在创建一个要绘制的位置数组,当我对数组使用 dma 时
,如果我声明数组的大小并填充,我可以让它工作,但如果我这样做,我
float *datac;
datac=NULL;
datac = new float[12];
datac[0] = 0;datac[1] = 0;datac[2] = 0;
datac[3] = 0;datac[4] = 100;datac[5] = 0;
datac[6] = 100;datac[7] = 100;datac[8] = 0;
datac[9] = 100;datac[10] = 0;datac[11] = 0;
//how do I pass it through to these functions
//this is what I was using when I done float datac[12] = ....
//I have tried using this sizeof(*datac)*sizeof(float)
//which compiles but just does not draw
glBufferData(GL_ARRAY_BUFFER, sizeof(datac), datac, GL_STATIC_DRAW);
glDrawArrays(GL_QUADS, 0, sizeof(datac)/ sizeof(float) / 3);
会陷入困境,我无法思考我需要什么要做
I am creating an array of positions to draw and I am stuck when I am using dma for the array
if I declare the size of the array and populate I can get it to work but if I do
float *datac;
datac=NULL;
datac = new float[12];
datac[0] = 0;datac[1] = 0;datac[2] = 0;
datac[3] = 0;datac[4] = 100;datac[5] = 0;
datac[6] = 100;datac[7] = 100;datac[8] = 0;
datac[9] = 100;datac[10] = 0;datac[11] = 0;
//how do I pass it through to these functions
//this is what I was using when I done float datac[12] = ....
//I have tried using this sizeof(*datac)*sizeof(float)
//which compiles but just does not draw
glBufferData(GL_ARRAY_BUFFER, sizeof(datac), datac, GL_STATIC_DRAW);
glDrawArrays(GL_QUADS, 0, sizeof(datac)/ sizeof(float) / 3);
Being dull and I cant think what I need to do
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它是 C++,因此您可以使用
std::vector
并让您的生活变得轻松:It's C++, so you can use
std::vector
and make your life easy:glBufferData 的第二个参数应该是 sizeof(float) * 12。
您还需要使用
gl*Pointer
函数指定数组。您似乎使用 Vec3 作为顶点,我相信默认值是 Vec4。例如:The second parameter to glBufferData should be
sizeof(float) * 12
.You also need to specify your arrays with the
gl*Pointer
functions. You seem to be using Vec3s for your vertices, I belive the default is Vec4. For example:嗯..是 glBufferData 的第二个参数
编辑:根据评论更正
sizeof(float)*12
Hmm.. is the second parameter to glBufferData
Edit: corrected per comments
sizeof(float)*12