Dynamic Texture Tiling

Is there any simple way to do texture tiling in a dynamic manner.



Basically I have a box which will change size dynamically and I want the texture on it to never stretch. So if the texture is 32x32 it should just tile a bunch of 32x32 textures to fit the entire box.



Right now it looks like I’d have to dynamically update the texture coords based on the dimensions of the box but that’s making my head hurt.



I was hoping there would be an easier way heh.

Have you tried experimenting with various values for Texture.setWrap()?

Try using Texture.WM_WRAP_S_WRAP_T as a value to wrap the texture. Also, if as the box resizes it doesn’t update with it, try using the Texture.setNeedsWrapRefresh() method. I’m new to jME so I haven’t tried any of these yet, but this is how you’d do it with other scenegraphs. I’m not sure if the setNeedsWrapRefresh() method needs to be called once or everytime it’s resized, you can try both ways; see which works.

I beleive you still have to set your texture coordinates appropriately for the setWrap() stuff to work.



So if you want something to wrap 5 times you need to set your coords to go from 0 to 5 instead of 0 to 1. I’m playing around with it now and it seems like it won’t be as hard as I thought to update the coords dynamically based on the box size so hopefully I can get it to work.

Yeah, I’m pretty sure you have to update the texcoords, but like you said, if you are already altering size, coords shouldn’t be too bad.

It’d be cool though if you could tell jME to apply a texture the exact number of times needed based on the size of the texture and the size of the object so that the texture never stretches.



I guess I’m so used to jME doing everything for me I feel like there’s something wrong when I actually have to think 8-O



A testament to either the power of jME or my laziness … probably a little bit of both hehe.

Heh true. You could make a controller or manager class to do that for you I suppose. I’m sure we’d be happy to add it into the utils if you did so…