I'm also trying to put together my Hello World, I only get a black screen with some lights (I think...) on. here is the code:
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import com.threed.jpct.Camera;
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.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.KeyMapper;
import com.threed.jpct.util.KeyState;
public class HelloWorld extends JFrame {
private FrameBuffer buffer = null;
private World world = null;
private TextureManager textureManager = null;
private Camera camera = null;
private int width = 640;
private int height = 480;
private Graphics g = null;
/**
* main method
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
HelloWorld h = new HelloWorld();
}
private boolean exit = false;
private int titleBarHeight;
private int leftBorderWidth;
private KeyMapper keyMapper;
private void gameLoop() {
World.setDefaultThread(Thread.currentThread());
buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
while (!exit) {
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
poll();
buffer.display(g, leftBorderWidth, titleBarHeight);
Thread.yield();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
System.exit(0);
}
/**
*/
public HelloWorld() {
setFrameStuff();
add3DStuff();
gameLoop();
}
private void setFrameStuff() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("jPCT Hello World (" + Config.getVersion() + ")");
pack();
Insets insets = getInsets();
titleBarHeight = insets.top;
leftBorderWidth = insets.left;
setSize(width + leftBorderWidth + insets.right, height + titleBarHeight
+ insets.bottom);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
g = getGraphics();
keyMapper = new KeyMapper(this);
}
private void add3DStuff() {
world = new World();
textureManager = TextureManager.getInstance();
Object3D box = Primitives.getBox(50, 50);
box.setOrigin(new SimpleVector(0, 0, 0));
world.addObject(box);
world.buildAllObjects();
/**
* Place the camera at the starting position.
*/
setCamera(box);
setLight();
}
private void setCamera(Object3D box) {
camera = world.getCamera();
camera.setPosition(0, 0, -180);
camera.lookAt(box.getTransformedCenter());
}
private void setLight() {
Config.fadeoutLight = false;
world.getLights().setOverbrightLighting(
Lights.OVERBRIGHT_LIGHTING_DISABLED);
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
world.setAmbientLight(25, 30, 30);
/**
* Place the lightsources...
*/
world.addLight(new SimpleVector(0, -150, 0), 25, 22, 19);
world.addLight(new SimpleVector(-100, -150, 100), 22, 5, 4);
world.addLight(new SimpleVector(100, -150, -100), 4, 2, 22);
}
/**
* Use the KeyMapper to poll the keyboard
*/
private void poll() {
KeyState state = null;
do {
state = keyMapper.poll();
if (state != KeyState.NONE) {
keyAffected(state);
}
} while (state != KeyState.NONE);
}
private void keyAffected(KeyState state) {
int code = state.getKeyCode();
boolean event = state.getState();
switch (code) {
case (KeyEvent.VK_ESCAPE): {
exit = event;
break;
}
}
}
}