How to load data from a plist for OpenGL Rendering (iPhone)?
I have an interesting problem. I have 4 arrays stored in a .plist file, they are called "vertices", "normals", "texCoords" and "polygo开发者_如何学Cns" (this file is attached, along with GLViewController.m). l want to load these arrays into arrays of type Vertex3D, Vector3D, GLfloat and GLubyte respectively, and then render them using OpenGL. However, I am unsure how load the arrays and was hoping you might be able to help. Bear in mind that I will want to modify the size of the arrays in the plist, so their size cannot be assumed to be constant (they could have any number of indices).
Links:
Plist: pastie.org/782396
GLViewController.m: pastie.org/782399
Plists are always loaded into arrays or dictionaries of "plist objects": NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary. So the only way to deal with them is to load the plist into an array or dictionary, then iterate through the resulting objects in order to build new arrays or whatever of the appropriate type.
So basically you'll need to write some sort of code to "translate" from plist to the object types needed by OpenGL.
Check out NSArray arrayWithContentsOfFile:
and NSDictionary dictionaryWithContentsOfFile:
Also see the Property List Programming Guide.
精彩评论