7
\$\begingroup\$

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?

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

1 Answer 1

10
\$\begingroup\$

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.

\$\endgroup\$
2
  • 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, 2013 at 18:17
  • \$\begingroup\$ to supplement sean's recommendations, also investigate glMapBufferRange and amd's pinned memory \$\endgroup\$
    – MickLH
    Jul 1, 2013 at 18:52

You must log in to answer this question.

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