Now I have written a small program which shows the problem.
2 worlds, 2 objects, 2 cameras but only left camera renders the scene.
(at software mode it runs great)
import java.awt.Canvas;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Lights;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
public class MainProgram implements Runnable {
private final int WIDTH=800, HEIGHT=600;
private World worldLeft, worldRight;
private Object3D objLeft, objRight;
private FrameBuffer bufferLeft, bufferRight;
private Canvas canvasLeft=null, canvasRight=null;
private float camStartX=0, camStartY=-30, camStartZ=-90;
private JFrame frame;
private int titleBarHeight, leftBorderWidth;
private boolean running=true;
public static void main(String[] args) throws Exception {
Config.glVerbose = true;
new MainProgram();
}
public MainProgram() throws Exception {
Config.maxPolysVisible=20000;
//frame
initFrame();
//world
worldLeft = createWorld();
worldRight = createWorld();
//object
objLeft = add3DObject(worldLeft);
objRight = add3DObject(worldRight);
//camera
adjustCamera(worldLeft, objLeft, true);
adjustCamera(worldRight, objRight, false);
initWorld();
new Thread(this).start();
}
private void initFrame() {
frame = new JFrame("OpenGL Stereoscopic Test");
frame.pack();
Insets insets = frame.getInsets();
titleBarHeight = insets.top;
leftBorderWidth = insets.left;
frame.setSize(WIDTH + leftBorderWidth + insets.right, HEIGHT + titleBarHeight + insets.bottom);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private World createWorld() {
// world
World world = new World();
// light
Config.fadeoutLight = false;
world.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
world.setAmbientLight(25, 30, 30);
world.addLight(new SimpleVector(-1000, -150, 1000), 8, 3, 2);
return world;
}
private Object3D add3DObject(World world) {
Object3D box = Primitives.getBox(13f, 2f);
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
return box;
}
private void adjustCamera(World world, Object3D obj, boolean left) {
float add = camStartX;
if (left) {
add = 14;
}
world.getCamera().setPosition(add, camStartY, camStartZ);
world.getCamera().lookAt(obj.getTransformedCenter());
}
private void initWorld() {
//layout
FlowLayout flLayout = new FlowLayout();
frame.setLayout(flLayout);
frame.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
//left side
bufferLeft = new FrameBuffer(WIDTH/2, HEIGHT, FrameBuffer.SAMPLINGMODE_NORMAL);
canvasLeft=bufferLeft.enableGLCanvasRenderer();
bufferLeft.disableRenderer(IRenderer.RENDERER_SOFTWARE);
canvasLeft.setSize(new Dimension(WIDTH/2, HEIGHT));
frame.add(canvasLeft);
//right side
bufferRight = new FrameBuffer(WIDTH/2, HEIGHT, FrameBuffer.SAMPLINGMODE_NORMAL);
canvasRight=bufferRight.enableGLCanvasRenderer();
bufferRight.disableRenderer(IRenderer.RENDERER_SOFTWARE);
canvasRight.setSize(new Dimension(WIDTH/2, HEIGHT));
frame.add(canvasRight);
}
private void loop() {
bufferLeft.clear(java.awt.Color.BLACK);
worldLeft.renderScene(bufferLeft);
worldLeft.draw(bufferLeft);
bufferLeft.update();
bufferLeft.displayGLOnly();
canvasLeft.repaint();
bufferRight.clear(java.awt.Color.BLACK);
worldRight.renderScene(bufferRight);
worldRight.draw(bufferRight);
bufferRight.update();
bufferRight.displayGLOnly();
canvasRight.repaint();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
}
Thread.yield();
}
@Override
public void run() {
while(running) {
loop();
}
bufferLeft.disableRenderer(IRenderer.RENDERER_OPENGL);
bufferLeft.dispose();
bufferRight.disableRenderer(IRenderer.RENDERER_OPENGL);
bufferRight.dispose();
frame.dispose();
System.exit(0);
}
}
If you are able to find a solution, please let me know.
Many many thanks!!!
Marlon