Hello,
I am sorry that I haven't written for so long - I have not had time to look at it and prepare example.
Well the problem with NullPointer seems to be that what you have said in some posts earlier ie. to not share objects between different FrameBuffers:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
public class Test2 extends JFrame implements Runnable
{
private static final long serialVersionUID = -1203822572518219468L;
private World world;
private FrameBuffer buffer;
private Canvas canvas;
private boolean initialized = false;
private FrameBuffer buffer2;
private Canvas canvas2;
private World world2;
private boolean alive = true;
public static void main(String[] args)
{
new Test2();
}
public Test2()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
pack();
setVisible(true);
}
private static World createWorld()
{
World w = new World();
w.setAmbientLight(100, 100, 100);
w.getCamera().setPosition(new SimpleVector(200, 0, 0));
w.getCamera().lookAt(SimpleVector.ORIGIN);
return w;
}
public void init()
{
world = createWorld();
world2 = createWorld();
Object3D BLUEPRINT = Primitives.getPyramide(10);
Object3D o1 = BLUEPRINT.cloneObject();
o1.compileAndStrip();
world.addObject(o1);
Object3D o2 = BLUEPRINT.cloneObject();
o2.compileAndStrip();
world2.addObject(o2);
buffer = createBuffer();
buffer2 = createBuffer();
add(canvas = buffer.enableGLCanvasRenderer(), BorderLayout.LINE_START);
add(canvas2 = buffer2.enableGLCanvasRenderer(), BorderLayout.LINE_END);
initialized = true;
new Thread(this).start();
}
private static FrameBuffer createBuffer()
{
FrameBuffer buffer = new FrameBuffer(300, 300,
FrameBuffer.SAMPLINGMODE_GL_AA_4X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
return buffer;
}
@Override
public void run()
{
while (alive)
{
this.repaint();
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
alive = false;
}
private static void paint(FrameBuffer buffer, World world, Canvas canvas)
{
buffer.clear(Color.BLACK);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
canvas.repaint();
}
@Override
public void paint(Graphics g)
{
if (!initialized)
return;
paint(buffer, world, canvas);
paint(buffer2, world2, canvas2);
}
}
Everything is fine if o2 is added to first world. If it is added to world2, the mentioned exception is thrown.
Thanks,
Wojtek