I had a look at the bones examples, but it did not get very clear to me. This is my first try, but when starting the app, nothing is rendered.
I initialize the BoxSoft Class to create the world, the camera and the framebuffer and give it as a Graphics to the canvas. I thought a loop is not necessary as the scene does not change or has any movement in it.
GUI:
package jPCT;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Canvas;
public class HelloGui extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
HelloGui frame = new HelloGui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public HelloGui() throws Exception {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 800, 600);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnTest = new JButton("Test 1");
btnTest.setBounds(10, 11, 89, 23);
contentPane.add(btnTest);
JButton btnTest_1 = new JButton("Test 2");
btnTest_1.setBounds(10, 45, 89, 23);
contentPane.add(btnTest_1);
JButton btnTest_2 = new JButton("Test 3");
btnTest_2.setBounds(10, 79, 89, 23);
contentPane.add(btnTest_2);
Canvas canvas = new Canvas();
canvas.setBounds(105, 10, 669, 542);
contentPane.add(canvas);
BoxSoft bs = new BoxSoft();
canvas.paint(bs.paint());
}
}
The "jPCT Class":
package jPCT;
import java.awt.Color;
import java.awt.Graphics;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.World;
public class BoxSoft {
private World world;
private FrameBuffer buffer;
private Object3D box;
public BoxSoft() {
world = new World();
// world.setAmbientLight(200, 255, 200);
// TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));
box = Primitives.getBox(3f, 2f);
// box.setTexture("box");
// box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.build();
world.addObject(box);
world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
buffer = new FrameBuffer(660, 540, FrameBuffer.SAMPLINGMODE_NORMAL);
}
public Graphics paint(){
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
world.drawWireframe(buffer, Color.WHITE);
buffer.update();
return buffer.getGraphics();
}
}