HelloWorld using LWJGL

Let’s get started! To create a window with a canvas to draw on (called a display) we use the following code:

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;

public class HelloWorld {
	public static void main (String args[]){
		try {
			Display.setTitle("Hello World");
		} catch (LWJGLException e) {

Easy! This creates a window the size of your current desktop with an area where the shapes we will later draw with OpenGL will appear. Unfortunately this window cannot be closed using the traditional ‘x’ button, you must shut down the java process itself. The next thing to do will be to add the close mechanism.

Add the following to the bottom of the main method:


Again, what this code does is obvious. We can see that the developers of LWJGL have tried to ensure that getting to the stage where we can start drawing shapes is as painless as possible.


OpenGL is an API specification for 2D and 3D graphics. It is implemented by hardware vendors on graphics cards or can be implemented in software. Hardware vendors pick and choose which operations are to be hardware accelerated.

All implementations can be accessed through a library of procedural C functions. More information about OpenGL can be found for free in the following book “The Red Book”. My favourite book on the subject is more mathematical than the previous one and is for sale here.

I like to develop in Java and hence use the JOGL library which translates the C functions into Java functions via the JNI. The functions are not wrapped, appearing as they would in C code. It would be nice to have a library written in an object oriented fashion (as is available for C++ here) but this is not available currently as far as I know. JOGL is available here.

LWJGL stands for the Light-Weight Java Gaming Library and is another library which gives you a lot of useful functions for writing games including windowing tools and precise timers. It is available here.

Hello world!

This is your my first post. My name is Phil and I am a software developer in the telecoms business. I will be using this blog to keep track of my current casual work. I hope you find it useful!