Here you go...it's from my game Naroth and it's actually targeted to font rendering, but that doesn't matter. The math stay the same, so it should help:
package com.threed.jpct.games.gui.glfont;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Texture;
/**
*
* @author EgonOlsen
*
*/
public class RenderTargetModifier implements CoordinateModifier {
private Texture target = null;
public RenderTargetModifier(Texture texture) {
target = texture;
}
@Override
public int convertX(FrameBuffer buffer, int x) {
return (int) ((float) x * ((float) buffer.getWidth() / (float) target.getWidth()));
}
@Override
public int convertY(FrameBuffer buffer, int y) {
return (int) ((float) y * ((float) buffer.getHeight() / (float) target.getHeight()));
}
@Override
public int getHeight() {
return target.getHeight();
}
}