1
\$\begingroup\$

I need to have tiles in my game, just 16x16 images, there would be hundreds (or even thousands) that make up a level. Of course it's not viable to have thousands of memory-hog normal entities, but tiles are just repeated images. What's the most memory-efficient way to do tiles?

\$\endgroup\$
  • \$\begingroup\$ You should check out Wang tiling if you are using a high tile count to try to overcome the fact that it is tiled. Wang tiling let's you get results that look organic and not tiled, while using only a small number of tiles. blog.demofox.org/2014/08/13/wang-tiling \$\endgroup\$ – Alan Wolfe Jul 24 '15 at 3:16
0
\$\begingroup\$

Load each image once then bind the texture before you draw the tile. Efficiency can be improved if you only draw tiles that will be visible or partially visible by the camera.

http://docs.gl/gl4/glGenTextures

http://docs.gl/gl4/glGenerateMipmap

http://docs.gl/gl4/glBindTexture

void init()
{
    //load geometry
    //load textures

    //Setup entities (geometry buffer ids and texture ids)
    //glGenTexture is very similar to glGenBuffer/glGenVertexArray
}

void draw()
{
    Entity e = //...

    glBindTexture(e.textureID);
    glBindVertexArray(e.vaoID);

    glDrawArrays(...);
}
\$\endgroup\$
0
\$\begingroup\$

Honeybunch answered for video memory I believe, I'm not that familiar with GL. But to store a map like that in memory and eventually on disk you need to think about what you want with the map. If you have less then 256 types of tiles and nothing else simply use a unsigned bytes in a array (vector in c++ right?). Having thousands of tiles is not that special anyway, I'm currently drawing 10K on my phone and not doing it efficiently ;).

\$\endgroup\$

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.