Ios4 如何在运行时在Objective-C(iOS)中动态创建数组?
我最近开始使用OpenGL在iOS应用程序中做一些事情 我发现本教程非常有帮助:Ios4 如何在运行时在Objective-C(iOS)中动态创建数组?,ios4,opengl-es-2.0,Ios4,Opengl Es 2.0,我最近开始使用OpenGL在iOS应用程序中做一些事情 我发现本教程非常有帮助: typedef struct { float Position[3]; float Color[4]; } Vertex; const Vertex Vertices[] = { ... }; const GLubyte Indices[] = { ... }; glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATI
typedef struct
{
float Position[3];
float Color[4];
} Vertex;
const Vertex Vertices[] = { ... };
const GLubyte Indices[] = { ... };
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
我需要一个变量/结构数组,因为内容依赖于运行时发生的事情,而不是静态的
当我直到运行时才知道数组中的元素数时,如何定义和创建动态数组
我需要使用malloc或类似的东西吗?我以前没有遇到过为iPhone应用程序分配内存的例子,所以我有点担心。如有任何建议或指示,我们将不胜感激。请与malloc联系:
Vertex* verts;
void Load()
{
int SIZE=200;
verts=(Vertex*)malloc(sizeof(Vertex)*SIZE);//in c you dont need (Vertex*)
}
对于malloc:
Vertex* verts;
void Load()
{
int SIZE=200;
verts=(Vertex*)malloc(sizeof(Vertex)*SIZE);//in c you dont need (Vertex*)
}
是的,您需要malloc()。或者,您可以依赖GCC扩展并编写
GLFloat顶点[someVariable]代码>是的,您需要malloc()。或者,您可以依赖GCC扩展并编写GLFloat顶点[someVariable]代码>你能展示一下你是如何用这个来储存Vert的吗?我已经尝试将顶点指定给顶点,但它不允许(预期表达式)。您能展示一下如何使用此选项存储顶点吗?我已尝试将顶点指定给顶点,但不允许(预期表达式)。