# Smallest, most memory-efficient way to have tiles? (C++/OpenGL)

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?

• 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 – Alan Wolfe Jul 24 '15 at 3:16

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()
{

//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(...);
}


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 ;).