Tile textures

Is there a way to? I have a box which I want to apply tectures on, but I don’t want them to be all stretched out.

Yep, check out TestAnisotropic for example. There I have the texture tiling 5 x 5 across the quad by using [0…5] range in my texturecoords and using setWrap(Texture.WM_WRAP_S_WRAP_T) on my Texture objects.

texture.setWrap() handles all the texture repeating, stretching clamping etc.



You’d want:



texture.setWrap(Texture.WM_WRAP_S_WRAP_T);



EDIT: Accidently submitted before I was finished ://



Once you have the wrap set, you’ll want to set the texture coordinates so that the texture is smaller than the quad (side) being applied to.



Cep does this in the starter’s guide, I believe.

And I realized that my explaination wasn’t every good regarding setting of the texture coordinates.



let’s say you normally have texture coordinates of:



(0,0)

(0,1)

(1,1)

(1,0)



to repeat the texture 2 times you’d do:



(0,0)

(0,2)

(2,2)

(2,0)



making the texture 1/2 of the original size on the object.



Hope that helps.

I can’t get it to work.



This is how I create the floor in the introduction level in Marble Fun:


// Creates the box that makes out the floor.
Box floor = new Box("Floor", new Vector3f(), 150, 0.5f, 150);
floor.setLocalTranslation(new Vector3f(0, 0, 0));

Texture dirt = ResourceManager.getInstance().getTexture("dirt.jpg");
dirt.setWrap(Texture.WM_WRAP_S_WRAP_T);
TextureState ground = TextureUtilities.getTextureState(dirt);

floor.setTextureCoord(0,0,new Vector2f(0,0));
floor.setTextureCoord(0,1,new Vector2f(0,2));
floor.setTextureCoord(0,2,new Vector2f(2,2));
floor.setTextureCoord(0,3,new Vector2f(2,0));
floor.updateTextureBuffer(0);

floor.setRenderState(ground);



I've tried lots of other values than 2, but still can't see any difference.

Seems ok, depends on what your TextureUtilities method does I suppose. Try using another texture that is easier to see repeats with, like the monkey image.

Nothing looks wrong from that snippet…



Have you tried a huge number like 50 or something? If there is no difference than for some reason the texture coords aren’t being updated.


depends on what your TextureUtilities method does I suppose


Yeah, sorry:


public static TextureState getTextureState(Texture texture) {
   TextureState ts = DisplaySystem.getDisplaySystem().
      getRenderer().createTextureState();
    ts.setEnabled(true);
    ts.setTexture(texture);
    return ts;
}




Try using another texture that is easier to see repeats with, like the monkey image.

Done that - no difference.


Have you tried a huge number like 50 or something?

I've tried all sorts of values without any luck.

Does my example in the starter guide work for you? I repeat the monkey texture bunches of times on a quad.

I’ll check it out, thanks!

Yes, it works :?

hehe, doh. Sorry I didn’t see this before, but you are using box to make a floor. Thus the coords you are referencing are on the top of the box, which you have set as width .5f Try changing it to

Box floor = new Box("Floor", new Vector3f(), 150, 150, 150);


and you'll see what I mean.

You'll need to use different texture coordinates to reference the front and back of the Box, or you might want to use Quad instead (as done in TestAnisotropic)

Thanks, got it working.