I'm trying to come up with some data structures for rendering my map on OpenGL. It is going to be ~ 100x100 blocks(squares) total, with each block being around 100 pixels. However, the screen will only display about 20x10 of these blocks at a time, depending on character location. So from this post:
It says that I shouldn't do a lot of allocation with ByteBuffers. So here are approaches I came up with:
- Allocate all 10,000 blocks, and simply change the vertices on every frame, for the ones I need to display. So no dynamic allocation, but a lot of up-front space.
- Only allocate blocks as I need them. So if in a frame I move left, and have to display new blocks, I will allocate 10 blocks in OpenGL. That way I have less memory allocated at once. However there is dynamic allocation and I need to set up the textures on every frame.
- Cache a few blocks of each type, and update the vertex information for them as I need them, that way I don't need to allocate a lot in the beginning, and I don't need to allocate anything dynamically. (So have 100 wall blocks, 100 door blocks, 100 floor blocks, all set up from the beginning)
Are any of these approaches the right way to go about doing this? Or how would one go about displaying a bunch of Bitmaps and updating their location on every frame? Or is Java a bad idea from the beginning, even for a simple 2D game?