Here is a modified NeHe tutorial that should explain it. You can cut and paste it and it should work as is. Make sure you link in the LWJGL library.
/*
* This Code Was Created By Jeff Molofee and GB Schmick 2000
* A HUGE Thanks To Fredric Echols For Cleaning Up
* And Optimizing The Base Code, Making It More Flexible!
* If You've Found This Code Useful, Please Let Me Know.
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
*/
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;
import org.lwjgl.input.Keyboard;
public class Test {
private boolean done = false;
private boolean fullscreen = false;
private final String windowTitle = "Centre of rotation";
private boolean f1 = false; // F1 key pressed
private DisplayMode displayMode;
private float rotate = 0.0f;
private float rotateVelocity = 0.0f;
private float transx = 0.0f;
private float transy = 0.0f;
public static void main(String args[]) {
boolean fullscreen = false;
if(args.length>0) {
if(args[0].equalsIgnoreCase("fullscreen")) {
fullscreen = true;
}
}
Test l23 = new Test();
l23.run(fullscreen);
}
public void run(boolean fullscreen) {
this.fullscreen = fullscreen;
try {
init();
while (!done) {
render();
mainloop();
Display.update();
}
cleanup();
}
catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private void mainloop() {
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Exit if Escape is pressed
done = true;
}
if(Display.isCloseRequested()) { // Exit if window is closed
done = true;
}
if(Keyboard.isKeyDown(Keyboard.KEY_F1) && !f1) { // Is F1 Being Pressed?
f1 = true; // Tell Program F1 Is Being Held
switchMode(); // Toggle Fullscreen / Windowed Mode
}
if(!Keyboard.isKeyDown(Keyboard.KEY_F1)) { // Is F1 Being Pressed?
f1 = false;
}
if(Keyboard.isKeyDown(Keyboard.KEY_PRIOR)) {
rotateVelocity += 0.001f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_NEXT)) {
rotateVelocity -= 0.001f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
transx -= 0.002f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
transx += 0.002f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
transy -= 0.002f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_UP)) {
transy += 0.002f;
}
}
private void switchMode() {
fullscreen = !fullscreen;
try {
Display.setFullscreen(fullscreen);
}
catch(Exception e) {
e.printStackTrace();
}
}
private void createWindow() throws Exception {
if (fullscreen) {
Display.setFullscreen(true);
}
else {
Display.setFullscreen(false);
}
DisplayMode d[] = Display.getAvailableDisplayModes();
for (int i = 0; i < d.length; i++) {
if (d[i].getWidth() == 640
&& d[i].getHeight() == 480
&& d[i].getBitsPerPixel() == 32) {
displayMode = d[i];
break;
}
}
Display.setDisplayMode(displayMode);
Display.setTitle(windowTitle);
Display.create();
}
private void init() throws Exception {
createWindow();
initGL();
}
private void initGL() { // All Setup For OpenGL Goes Here
int width = 640;
int height = 480;
GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
GL11.glClearDepth(1.0f); // Depth Buffer Setup
GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); // Really Nice Perspective Calculations
GL11.glViewport(0,0,width,height); // Reset The Current Viewport
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
GL11.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(45.0f,
(float) displayMode.getWidth() / (float) displayMode.getHeight(),
0.1f,100.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
GL11.glLoadIdentity(); // Reset The Modelview Matrix
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
GL11.glTranslatef(transx, transy, -6.0f);
GL11.glRotatef(rotate, 0.0f, 0.0f, 1.0f);
GL11.glBegin(GL11.GL_TRIANGLES);
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(-1.0f, 1.0f, 0.0f);
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f( 1.0f, 1.0f, 0.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f( 0.0f, 0.0f, 0.0f);
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f( 1.0f, 1.0f, 0.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f( 1.0f,-1.0f, 0.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f( 0.0f, 0.0f, 0.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f( 1.0f,-1.0f, 0.0f);
GL11.glColor3f(1.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f,-1.0f, 0.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f( 0.0f, 0.0f, 0.0f);
GL11.glColor3f(1.0f, 0.0f, 1.0f);
GL11.glVertex3f(-1.0f,-1.0f, 0.0f);
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(-1.0f, 1.0f, 0.0f);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glVertex3f( 0.0f, 0.0f, 0.0f);
GL11.glEnd();
rotate += rotateVelocity;
}
private void cleanup() {
Display.destroy();
}
}