2
\$\begingroup\$

I have a VBO, which I initialise like this (just an example):

- (void)setupVBOs {

    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

    GLuint indexBuffer;
    glGenBuffers(1, &indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);

}

As you can see, I'm using GL_STATIC_DRAW, which is good for visually unchanging objects (not including translations and such).

How do I draw animated objects though? I mean things that might be changed by user interaction. This video is a good example. It is obvious OpenGL is being used, as the vertices are manipulated by gestures.

How is it done? by changing the x y z coordinates on every touch? Are they using GL_DYNAMIC_DRAW? Is this hard?

\$\endgroup\$
0

1 Answer 1

3
\$\begingroup\$

Create a VBO with a GL_DYNAMIC_DRAW or GL_STREAM_DRAW flag. This is used to give the OpenGL implemetation a hint of where to allocate the memory and enable certain optimizations, for example the data could be cached or not, stored in system memory or graphics memory.

Dynamic means the data will be changed frequently (specified and used repeatedly)

Stream means the data will be changed every frame (specified once and used once).

Regarding the video, since you are going to update the buffer frequently, once you create your buffer, you can use glMapBuffer which will give you the ability to map the buffer in the GPU to the client address and directly read and/or write on it relative to the returned pointer, depending on the specified access policy. This way you can update the vertices frequently without copying the entire buffer every time.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks! are there any online tutorials or examples you know of? \$\endgroup\$
    – Itzik984
    Commented Feb 2, 2014 at 23:18
  • \$\begingroup\$ @Itzik984 tutorials regarding which topic exactly ? \$\endgroup\$
    – concept3d
    Commented Feb 2, 2014 at 23:23
  • \$\begingroup\$ about how to use glMapBuffer and get/set the needed data. just to prevent myself for wondering in the dark regarding these issues. \$\endgroup\$
    – Itzik984
    Commented Feb 2, 2014 at 23:29
  • \$\begingroup\$ @Itzik984 This one I used previously songho.ca/opengl/gl_vbo.html it has clear src code for dynamic VBOs \$\endgroup\$
    – concept3d
    Commented Feb 2, 2014 at 23:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .