GLfloat* v = CPATriangleVerticies(0.5, 0.5, 0.5);
GLuint VBO;
glGenBuffers(1, &VBO);
//Tell it we are sending an array
glBindBuffer(GL_ARRAY_BUFFER, VBO);
//Tell it the data
glBufferData(GL_ARRAY_BUFFER, sizeof(*v), v, GL_STATIC_DRAW);
Is this safe, or will the array not be passed properly. This question really has nothing to do with opengl I just need to know that it is safe to do stuff like this. Thanks!
CPATriangleVerticies() shouldn't allocate the array at all, it should just populate it. This is much more flexible since the caller can decide where the array is allocated:
GLfloat v[9];
CPATriangleVerticies(0.5, 0.5, 0.5, v);
GLuint VBO;
glGenBuffers(1, &VBO);
//Tell it we are sending an array
glBindBuffer(GL_ARRAY_BUFFER, VBO);
//Tell it the data
glBufferData(GL_ARRAY_BUFFER, sizeof(v), v, GL_STATIC_DRAW);
By the way, what is the 2nd parameter to glBufferData? I'm passing the number of bytes in the array. Is that right or should it be the number of items in the array?