我的 OpenGL ES 应用程序中有以下 Vertex 结构:
typedef struct Vertex {
float Position[3];
float Color[4];
} Vertex;
然后在我的标题中声明:
Vertex *Vertices;
然后在我的初始化方法中:
int array = 4;
Vertices = (Vertex *)malloc(array * sizeof(Vertex));
然后我按如下方式设置网格,在这种情况下,顶点数组有 4 个顶点:
- (void)setupMesh {
int count = 0;
for (VerticeObject * object in verticesArray) {
Vertices[count].Position[0] = object.x;
Vertices[count].Position[1] = object.y;
Vertices[count].Position[2] = object.z;
Vertices[count].Color[0] = 0.9f;
Vertices[count].Color[1] = 0.9f;
Vertices[count].Color[2] = 0.9f;
Vertices[count].Color[3] = 1.0f;
count ++;
}
}
谁能发现我在这里做错了什么?当我将此 Vertices 对象传递给 OpenGL 时,不会绘制任何内容,而如果我将 Vertices 数组硬编码为:
Vertex Vertices [] = {
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
{{0.0 , 0.0 , 0}, {0.9, 0.9, 0.9, 1}},
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
{{0.0, 0.0, 0}, {0.9, 0.9, 0.9, 1}},
};
一切正常?