I am learning LWJGL so i can start working on my game. In order to learn LWJGL I got the idea to implement the map builder so I can get comfortable with graphics programming. Now, for the map creation tool I need to draw new elements or draw the old one's with different coordinates.

Let me explain this:

My game will be a 2D scroller. The map will be consisting of multiple rectangles ( 2 strip triangles). When I click my left-mouse button i want to start the rectangle and when I release it I want to stop the rectangle bottom-right at that position.

As I want to use VBOs I want to know how to modify data inside the VBO based on user input. Should i have a copy of a vertex array and then add the whole array to the VBO at each user input? How is usually implemented the VBO update?

  • 1
    \$\begingroup\$ Check out: glBufferSubData. Though, it's probably easier to just make the buffer again. \$\endgroup\$
    – MichaelHouse
    Jul 1 '13 at 17:22

For small data like this, you want glBufferSubData, sweet and simple :)

Later on you probably should look into glMapBuffer though, as it is how you work with data larger than a few kilobytes quickly.

  • 5
    \$\begingroup\$ Note that you should use glInvalidateBufferData as appropriate, or for older GL, use the trick of calling glBufferData first with a NULL address and 0 length. This will allow the GPU to intelligently handle your data updates without stalling in the event you are updating the buffer while the GPU is still drawing from it. \$\endgroup\$ Jul 1 '13 at 18:17
  • \$\begingroup\$ to supplement sean's recommendations, also investigate glMapBufferRange and amd's pinned memory \$\endgroup\$
    – MickLH
    Jul 1 '13 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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