我在我的OpenGL ES应用中的以下顶点结构:正在初始化一个C结构阵列 - 目标C - OpenGLES
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 ++;
}
}
任何人都可以发现我在这里做错了吗?当我通过这个顶点对象的OpenGL什么也不绘制,而如果我硬编码的顶点数组:
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}},
};
一切正常?
当您在初始化后检查调试器中的第一个数组时,它看起来像您期望的那样吗? (即,它看起来与第二种情况相同吗?) –
另外,你如何初始化verticesArray? – micantox
本 - 是的 - 数组看起来不错。 – GuybrushThreepwood