Hi,
I was searching this forum for answer but I was not able to find any:-(
Is there a way how to render just part of the loaded texture?
E.g. I load texture of size 100x100, but I would like to render only viewport of it - let's say from [25, 25] to [75,75]. Is that possible??
Right now I'm able to move the texture at [25,25] with texture.getTranslation().set(0.25f, 0.25f, 0);
But this is not enough - I need also to restrict the end point [75,75].
Thanks for answer
you can get the TextureCoordinates from a Geometry and set them to 0.25 and 0.75 instead of 0 and 1. This would result in what you want i guess.
You can do this two ways, by changing the texture coordinates of your object, or by a combination or translation and "zoom" (getScale/setScale) of your texture.
Thanks guys,
that's exactly what I needed.
Maybe this example helps you.
//Quad
Quad q = new Quad("quad", 100, 200);
q.setLocalTranslation(100, 0, 0);
q.setModelBound(new BoundingBox());
ArrayList<TexCoords> tc = q.getTextureCoords();
FloatBuffer fb;
for(int i=0;i<tc.size();i++){
fb=tc.get(i).coords;
System.err.println("Coords :");
fb.flip();
while(fb.hasRemaining()){
System.err.println(fb.get());
}
}
FloatBuffer fbm=BufferUtils.createFloatBuffer(8);
fbm.put(0f);
fbm.put(0.5f);
fbm.put(0f);
fbm.put(0f);
fbm.put(0.5f);
fbm.put(0f);
fbm.put(0.5f);
fbm.put(0.5f);
TexCoords tcm=new TexCoords(fbm);
q.setTextureCoords(tcm);
tc = q.getTextureCoords();
for(int i=0;i<tc.size();i++){
fb=tc.get(i).coords;
System.err.println("Coords :");
fb.flip();
while(fb.hasRemaining()){
System.err.println(fb.get());
}
}
q.setRenderQueueMode(Renderer.QUEUE_ORTHO);
q.updateRenderState();
n.attachChild(q);