Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
@Anko I don't agree that it is a moving object, I think animated would be more accurate, –  concept3d Feb 2 at 23:40
    
@concept3d I see what you mean, now that I'm not blinded by the review queue showing only the question. I edited again. Is it better? –  Anko Feb 2 at 23:43
    
@Anko Yes. I think it's more accurate now. Am not a fan of the review queue presentation either :) –  concept3d Feb 2 at 23:46

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks! are there any online tutorials or examples you know of? –  Itzik984 Feb 2 at 23:18
    
@Itzik984 tutorials regarding which topic exactly ? –  concept3d Feb 2 at 23:23
    
about how to use glMapBuffer and get/set the needed data. just to prevent myself for wondering in the dark regarding these issues. –  Itzik984 Feb 2 at 23:29
    
@Itzik984 This one I used previously songho.ca/opengl/gl_vbo.html it has clear src code for dynamic VBOs –  concept3d Feb 2 at 23:39
    
great. thanks a lot! will look into it. –  Itzik984 Feb 2 at 23:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.