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