LWJGL Forum

Programming => OpenGL => Topic started by: scorsh on November 14, 2013, 12:02:29

Title: Repeating textures and texture atlas?
Post by: scorsh on November 14, 2013, 12:02:29
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?




Title: Re: Repeating textures and texture atlas?
Post by: scorsh on November 15, 2013, 12:32:31
As discussed in http://stackoverflow.com/questions/662107/how-to-use-gl-repeat-to-repeat-only-a-selection-of-a-texture-atlas-opengl, it cannot be done.
Title: Re: Repeating textures and texture atlas?
Post by: quew8 on November 15, 2013, 17:38:11
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.
Title: Re: Repeating textures and texture atlas?
Post by: scorsh on November 16, 2013, 13:37:27
Thanks for the confirmation. I'm changing my approach.