gpt4 book ai didi

c++ - opengl vbo dma 数组

转载 作者:搜寻专家 更新时间:2023-10-31 01:58:16 24 4
gpt4 key购买 nike

我正在创建要绘制的位置数组,但在为数组使用 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);

头脑迟钝,想不出自己需要做什么

最佳答案

它是 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);

关于c++ - opengl vbo dma 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com