我在我的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