0

I would like to store the vertex, normal, and texture information for my Cat objects within each instance in the form of a Vertex Buffer Object, but I don't know how. I want something like this:

@property(nonatomic, assign) int *indices; // vertex indices for glDrawElements
@property(nonatomic, assign) GLKVertexAttrib vertexBufferObject; // ideally
@property(assign) GLKVector2 position;
@property(assign) GLKVector2 velocity;

If you can't create objects that contain specific VBOs, what do you do?

michaelsnowden
  • 6,031
  • 2
  • 38
  • 83

1 Answers1

0

I ended up doing this:

@property(nonatomic, assign) int *indices;
@property(nonatomic, assign) GLuint vertexBuffer; // good
@property(assign) GLKVector2 position;
@property(assign) GLKVector2 velocity;

- (id)initWithVertices: (SceneVertex [])vertices size: (uint) size; // very good
- (void)render;

and then this:

- (id) initWithVertices:(SceneVertex [])vertices size:(uint)size
{
    if (self = [super init])
    {
        glGenBuffers(1, &_vertexBuffer);
        glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);

        glBufferData(GL_ARRAY_BUFFER, size * sizeof(SceneVertex), vertices, GL_STATIC_DRAW);

        glEnableVertexAttribArray(GLKVertexAttribPosition);
        int stride = sizeof(GLKVector3) * 2;
        glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(0));
        glEnableVertexAttribArray(GLKVertexAttribNormal);
        glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(sizeof(GLKVector3)));
    }

    return self;
}

And it worked out just fine. Now all my information is contained within each object. Awesome!

michaelsnowden
  • 6,031
  • 2
  • 38
  • 83