Question

Just been learning some OpenGL on android learning the basics of making a game.

The trouble I'm having is to do with mapping different textures "per tile" onto my grid.

For instance:

I have a grid of tiles - 8x8 - in my vertex array I define the grid by defining a 9x9 vertices to construct the columns/rows. I then go and make an index buffer telling it how to draw the 2 triangles that make up each square in the grid.

My frustration lies in mapping textures to different tiles of the grid as each square SHARES vertices with other squares in the grid, and as far as I know you can only apply one texture coord per vertices in Opengl.

The only solution I can think of is to generate duplicate vertices in the vertex buffer which would allow me to assign individual texture coordinates per vertex (even though the vertex would already be in the buffer from the generation of the previous tile). This way would end me up with a whole heap of duplicate vertices which in my head doesnt seem right. I also want to avoid having to dynamically create a large bitmap and then map it onto the grid with fractional texture coords.

Can someone please educate my novice mind on how I go about getting different textures per tile on a grid!

Thanks!

Was it helpful?

Solution

The only solution I can think of is to generate duplicate vertices in the vertex buffer which would allow me to assign individual texture coordinates per vertex

This is exactly what you should do. It may seem wasteful, but a "vertex" to opengl is a collection of ALL the attributes that define a vertex (including texcoords, normals, etc). If one physical vertex position is shared by 4 quads, but the texcoord of that point differs for each quad, than you must create 4 unique vertices and indices to refer to that point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top