Here's a class that scales a texture to fit the screen by actually scaling a textured plane. It requires the lastest 116rc2-version (available from the news-section and updated today(!) (without changing the name...so if you already downloaded 116rc2 before, grab it again)) to work correctly. If you can't or don't want to use 116rc2, you have to put a world.renderScene(<FrameBuffer>) in the first line of the adjustPlane()-method as a workaround.
The basic idea of this approach is to make a textured plane fill the whole screen no matter where the camera is looking. This way, you can use this for a single World with no camera movement just to paint the scaled texture or for a complex world with lots of objects as a backdrop, transparent overlay or whatever...
Maybe i should add this to the util-package...it seems to be handy for some things...
import com.threed.jpct.*;
public class ScreenFiller {
private World world;
private FrameBuffer buffer;
private Object3D plane;
private MyController adjuster=null;
public static void main(String[] args) throws Exception {
new ScreenFiller().loop();
}
public ScreenFiller() throws Exception {
world = new World();
TextureManager.getInstance().addTexture("planeTex", new Texture("alpha.png"));
plane = Primitives.getPlane(1, 1);
plane.setTexture("planeTex");
plane.build();
plane.setAdditionalColor(java.awt.Color.WHITE);
world.addObject(plane);
plane.build();
adjuster=new MyController();
plane.getMesh().setVertexController(adjuster, IVertexController.PRESERVE_SOURCE_MESH);
}
private void adjustPlane() {
float depth=10f; // Can be almost anything, but i think 10 is reasonable
SimpleVector upperLeft=Interact2D.reproject2D3D(world.getCamera(), buffer, 0, 0, depth);
SimpleVector lowerLeft=Interact2D.reproject2D3D(world.getCamera(), buffer, 0, buffer.getOutputHeight(), depth);
SimpleVector lowerRight=Interact2D.reproject2D3D(world.getCamera(), buffer, buffer.getOutputWidth(), buffer.getOutputHeight(), depth);
SimpleVector upperRight=Interact2D.reproject2D3D(world.getCamera(), buffer, buffer.getOutputWidth(), 0, depth);
Matrix camMat=world.getCamera().getBack().cloneMatrix();
SimpleVector camPos=world.getCamera().getPosition();
camPos.matMul(camMat);
upperLeft.add(camPos);
lowerLeft.add(camPos);
lowerRight.add(camPos);
upperRight.add(camPos);
Matrix resMat=camMat.invert3x3();
upperLeft.matMul(resMat);
lowerLeft.matMul(resMat);
lowerRight.matMul(resMat);
upperRight.matMul(resMat);
adjuster.setNewBounds(upperLeft, lowerLeft, upperRight, lowerRight);
plane.getMesh().applyVertexController();
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
// The adjustPlane()-method is flexible enough to handle arbitrary camera positions.
// world.getCamera().rotateY((float)Math.PI/12.45555f);
// world.getCamera().moveCamera(Camera.CAMERA_MOVEIN, 50f);
adjustPlane();
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
Thread.sleep(100);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}
private static class MyController extends GenericVertexController {
private SimpleVector[] poss=new SimpleVector[4];
public void apply() {
SimpleVector[] dstMesh=this.getDestinationMesh();
for (int i=0; i<4; i++) {
dstMesh[i]=poss[i];
}
}
public void setNewBounds(SimpleVector ul, SimpleVector ll, SimpleVector ur, SimpleVector lr) {
poss[0]=ul;
poss[1]=ll;
poss[2]=ur;
poss[3]=lr;
}
}
}