0

我最近开始使用 OpenGL 在我的 iOS 应用程序中做一些事情。

我发现这个教程很有帮助:

www.raywenderlich.com/3664/opengl-es-2-0-for-iphone-tutorial

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 应用程序分配内存的例子,所以我有点警惕。任何建议或方向将不胜感激。

4

1 回答 1

3

使用 malloc:

    Vertex* verts;
    void Load()
    {
        int SIZE=200;
        verts=(Vertex*)malloc(sizeof(Vertex)*SIZE);//in c you dont need (Vertex*)
    }
于 2012-07-21T18:40:28.020 回答