Texture wrapping on a per object basis

Hello!



How can i adjust the texture wrapping / tiling for different objects (Boxes for example), that use the same texture?

Basically i want the texture to have a fixed size and when the object is larger than this size the texture shall be tiled,

rather than streched.



Somewhere in the forum I found the method setTextureCoord, but it doesn't seem to exist anymore.



Thanks for any tips in advance.

yourTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);


Will make your texture wrap.
To set texture coordinates on an object, you can just


FloatBuffer tex = your3dObject.getTextureBuffer(0, 0); //getTextureBuffer(int batchIndex, int textureUnit)


and manipulate the buffer directly. Just don't forget to call your3dObject.updateGeometricState() after that.

Thanks! That works.



It's a simple thing to do for a box, however, for spheres and cylinders it's going to get a bit complicated, i guess.

You can use texture matrices to set a scale, simply call Texture.setScale() with the scale value and you will not have to do any modification to the coordinates.

Ok that might work, but if i want to adjust the texture scale for some objects using the same texture individually, don't i have to create seperate textures for each of those objects?



I tried with setScale, and it is way better, of course. But my problem is, as already mentioned, that i have a few objects sharing the same texture who would need different texture scales. :slight_smile:

I am not sure how is it in OpenGL, I believe that texture matrix is a GL state property, not texture object property, will have to verify this. If it's a state property you might be able to do it with a shared texture: Texture.createSimpleClone()

The texture matrix is a GL state. It is altered with usual glPushMatrix(), glPopMatrix(), glMatrixMode(GL_TEXTURE)…

It's kept and matched per texture unit, so you should be able to simply clone your texture (with createSimpleClone())  and set a different matrix / scale on each.

hevee said:

yourTexture.setWrap(Texture.WM_WRAP_S_WRAP_T);


Will make your texture wrap.
To set texture coordinates on an object, you can just


FloatBuffer tex = your3dObject.getTextureBuffer(0, 0); //getTextureBuffer(int batchIndex, int textureUnit)


and manipulate the buffer directly. Just don't forget to call your3dObject.updateGeometricState() after that.


I've got a skybox where I want to tile a small texture of some clouds in a repeating pattern.  Skybox has no visible texture buffer that I can see.  Is there an example somewhere of how to do this?

I don't have the code in front of me, but you should be able to grab the skybox face and set it there.

Sorry to be completely clueless,  but what do you mean by skybox face?  I didn't really understand the texture coordinate snippet above either.  I know that the texture has coordinates and those get mapped to the geometry somehow, but how it actually works is something of a black box to me.  My college grpahics class was over 10 years ago and I haven't touched anything like it since until now.

A Skybox is just a "box" with 6 faces (Quads) oriented to look inwards.  You can access each face (or Quad) in jME 1.0 via the method: getSide(int)  (it's getFace(Face) in 2.0 fwiw)

renanse said:

A Skybox is just a "box" with 6 faces (Quads) oriented to look inwards.  You can access each face (or Quad) in jME 1.0 via the method: getSide(int)  (it's getFace(Face) in 2.0 fwiw)


I saw in another thread that you set the texture scale to the number of times you want it to repeat.  That makes sense.  I'm not sure what all this was about then.



FloatBuffer tex = your3dObject.getTextureBuffer(0, 0); //getTextureBuffer(int batchIndex, int textureUnit)


and manipulate the buffer directly. Just don't forget to call your3dObject.updateGeometricState() after that.


Am I missing something?