Texture Coordinates Buffer Problem with multitexturing


I'm having a problem to modify a texture coordinates buffer. I have a quad with two textures. I  want to apply images of different size on this quad. The setting is ok if I have one texture but as soon as I have too the only possible thing is to access to the first buffer and copy it to the second one, otherwize I get a NullPointerException :

FloatBuffer[] texCoordBuffer = this.getTextureBuffers(0);

So right now I'm only using images of same size, doing a copyTextureCoords(0,0,i) at the end, but I really need to setup the second texture coordinates buffer.

Do you know where the problem come from?
Thanks for your help,

Boris G.

I still don't find the problem, does someone know?

When you use multiple textures on an object, you also need to supply multiple coord channels.  So, I'm not sure what problem you are talking about?

Hello and thanks for your answer,

That's actually the problem, I don't manage to setup the coordinates channel, only the first one (0). If I try to access to the second one, with texCoordBuffer[1].rewind() for example, I'll get a null pointer exception error. But if I simply copy the texture coordinates buffer with copyTextureCoords(0,0,1), it will work.

I don't understand why, so maybe I'm wrong and what I'm doing is not setting up an other coordinates channel, in that case how do you do that?

Thanks for your help,


Yeah, quads (or any of the primitives) only come with coords for 1 texture slot.  If you put textures in other slots, you'll need to either make you own new FloatBuffer and set it into those slots or use copyTextureCoords to copy the 0th texture coords to the other slots.

DEV NOTE: Perhaps we should change this in 2.0 so that if the tex coords in a slot are null it will reuse the first non-null texcoords.

Thanks, everything is clear now :slight_smile:

For now what I'm doing is resizing the textures to the same size and then copy the texture coordinates buffer, it works fine even if it's quite heavy.

I'll try to use my own float buffer,

Thanks again,


I'm curious why you need to resize your textures?  texture coords are not size dependent.  Unless you mean chop them down to just the part you need?

Hi,Thats actually the point, If I want textures to keep a wanted position (one specific point has to be on an other specific point) the textures coordinates will not correspond if I don't set the two images to be the same size.

If you mean pixel wise (like a spot that is 5 pixels from the left and 5 from the top), then yeah, gotcha.  In that case you could also set a scale on the texture, or multiply your texcoords by the ratio difference in sizes

Otherwise, if you mean the same spot in terms of ratio then even if you had a texture that was say 100x100 and a texture that was 200x200, a spot that is 1/4th of the way from the left and 1/4th of the way from the bottom on both (as an example) will line up even though one is at 25,25 (pixel wise) and the other is at 50,50.