Repeating textures and texture atlas?

Started by scorsh, November 14, 2013, 12:02:29

Previous topic - Next topic

scorsh

I'm writing a block engine for fun. Right now, it generates chunks of dirt blocks. I put all the vertices, etc. into an interleaved VBO. I also have a very simplistic pair of shaders.

To cut down on the number of vertices, it renders only the block faces that are visible taking into account neighboring chunks.

It also consolidates a horizontal run of identical blocks into 1 set of 4 vertices. For example, if there are 16 visible dirt blocks in a row on the X axis then it uses the 2 left-most vertices from the 1st block and the 2 right-most vertices from the 16th block. So that the dirt texture renders per block instead of being stretched across 16 blocks, I adjust the UV coordinates to match the # of blocks (e.g., { (0:0), (0:1), (16:1), (16:0) } and tell OpenGL to repeat the texture. That works fine and it renders 225 chunks without a hitch.

My next step is to incorporate a stone block with its own texture.

If I were putting the vertices for each block into the VBO, I know that I could make a texture atlas containing the 2 textures and I could specify the UV coordinates of the texture to use for each block. In this case, my understanding is that UV coordinates would be fractional values between 0 and 1.

But what can I do in this situation where I am repeating textures? It doesn't seem like I can use a texture atlas in this case because of how I am adjusting the texture coordinates to cause the repetition.

Am I approaching this from the wrong angle?






quew8

And, whilst your optimization is a good idea and you could still use it sometimes, I would advice using a texture atlas first and foremost. The video cards can handle doing 10x as many vertices as long as you aren't switching between 10 textures.

scorsh

Thanks for the confirmation. I'm changing my approach.