Hi there,
I'm pretty new to Objective-C and even C in general here, so please bear with me. My main goal is to display my NSMutableArray of CGPoints (via NSValue) with glDrawArrays(GL_LINE_STRIP, 0, points);
I noticed that cocos2d requires an array(?) pointer *poli
like so:
void ccDrawPoly( CGPoint *poli, int points, BOOL closePolygon ) { ... }
So I tried to convert my NSMutableArray to a C array and I can access/debug the CGPoints just fine:
NSUInteger count = [points count];
id *buffer = malloc(sizeof(NSValue) * count);
[points getObjects: buffer];
for(uint i = 0; i < count; i++) {
NSValue *val = buffer[i];
CGPoint p = [val CGPointValue];
NSLog(@"points x %i: %f", i, p.x);
/* shows up in the console as:
-----------points at 0: 42.000000
-----------points at 1: 44.000000
... etc
*/
}
free(buffer);
But I guess where I'm stuck is getting them into a data type that either ccDrawPoly
or glDrawArrays(GL_LINE_STRIP, 0, points)
will accept. Which is apparently a struct or something, but I'm not sure how to get them into a struct.
Any help would be greatly appreciated! Thanks!