opengl vbo dma数组

发布于 2024-10-04 22:33:37 字数 686 浏览 10 评论 0原文

我正在创建一个要绘制的位置数组,当我对数组使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蝶舞 2024-10-11 22:33:37

它是 C++,因此您可以使用 std::vector 并让您的生活变得轻松:

std::vector<float> datac(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;

glBufferData(GL_ARRAY_BUFFER, datac.size()*sizeof(float), &datac[0], GL_STATIC_DRAW);
// glVertexPointer in GL2 or glAttribPointer in GL3 comes here
glDrawArrays(GL_QUADS, 0, datac.size() / 3);

It's C++, so you can use std::vector and make your life easy:

std::vector<float> datac(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;

glBufferData(GL_ARRAY_BUFFER, datac.size()*sizeof(float), &datac[0], GL_STATIC_DRAW);
// glVertexPointer in GL2 or glAttribPointer in GL3 comes here
glDrawArrays(GL_QUADS, 0, datac.size() / 3);
徒留西风 2024-10-11 22:33:37

glBufferData 的第二个参数应该是 sizeof(float) * 12。

您还需要使用 gl*Pointer 函数指定数组。您似乎使用 Vec3 作为顶点,我相信默认值是 Vec4。例如:

GLuint VertexBuf;
glGenBuffers(1, &VertexBuf);
glBindBuffer(GL_ARRAY_BUFFER, VertexBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*12, datac, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);

glDrawArrays(GL_QUADS, 0, sizeof(float) * (12 / 3));

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:

GLuint VertexBuf;
glGenBuffers(1, &VertexBuf);
glBindBuffer(GL_ARRAY_BUFFER, VertexBuf);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*12, datac, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);

glDrawArrays(GL_QUADS, 0, sizeof(float) * (12 / 3));
原来分手还会想你 2024-10-11 22:33:37

嗯..是 glBufferData 的第二个参数

sizeof(datac)*12

编辑:根据评论更正

sizeof(float)*12

Hmm.. is the second parameter to glBufferData

sizeof(datac)*12

Edit: corrected per comments

sizeof(float)*12

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文