我有一个名为 mVerticies 的 NSMutableArray 存储为我的类的成员,我想将它们放入 float 组中以使用 glVertexAttribPointer 绘制它们。 p>
通常在画画的时候,我会有这样的东西:
float verticies[] = {-1, -1, 1, -1};
// ... prepare to draw
glVertexAttribPointer(GLKVertexAttribPosition,
2, GL_FLOAT, GL_FALSE, 0, verticies);
// ... draw
但是为了使用 glVertexAttribPointer 函数,我需要一个 float[]。 verticies 存储为 NSMutableArray 因为它们经常更改。有没有一种简单的方法可以将动态 float[] 存储为成员或快速将 NSMutableArray 转换为 float[]?
最佳答案
假设值存储为 NSNumbers,你可以这样做:
float *floatsArray = malloc([numbersArray count] * sizeof(float));
if (floatsArray == NULL) {
// handle error
}
[numbersArray enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(NSNumber *number, NSUInteger idx, BOOL *stop) {
floatsArray[idx] = [number floatValue];
}];
// use floatsArray
free(floatsArray);
关于objective-c - 将 NSMutableArray 复制到 float 组中以进行 GLES 渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9285559/