NSArray to dynamic C-array
Hi all,
I'm working on a simple Obj-C Graphics Library but I'm stuck with a very annoying issue.
I've got the following two structs:
typedef struct _GLVector4 {
float x;
float y;
float z;
float w;
} GLVector4;
and
typedef struct _GLRawVertex {
GLVector4 position;
GLVector4 color;
} GLRawVertex;
I want to initialize an array of GLRawVertex's so I define:
GLRawVertex *rawVertexData;
Now when I want to store data, I've got two options:
GLRawVertex otherVertices[] = {
{{0,0,0,1},{0,1,0,1}},
{{1,0,0,1},{1,0,0,1}},
{{0,1,0,1},{0,0,1,1}}};
or
rawVertexData = new GLRawVertex[3];
int i = 0;
for (GLVertex *currentVertex in vertices){
rawVertexData[i].position = currentVertex.position;
rawVertexData[i].color = currentVertex.color;
i++;
}
where in the last part GLVertex is a simple Obj-C class with GLVector4 properties for position and color. Position and color contain the same values as in the static array declaration. When I NSLog them this is confirmed.
For some strange reason OpenGL draws fine with the first part, but when I initialize the array dynamically nothing is drawn on the screen.
Does somebody know where the second part fails? How can I create dynamic arrays in C? My source-code file is a .mm and the XCode file-type is Objective-C++.
Thanks for your help!
|