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.


4 thoughts on “HelloWorld using LWJGL

    1. Thread.sleep() throws an InterruptedException. Put that statement in

      catch(Exception e){

      1. Because he never initialized a thread via when you put the public class HelloWorld{
        you are supposed to put implements Runnable and then inside the main thing you then put Thread whatEverTheNameIs = new Thread(mainGameLoop);
        the take everything out of the main function and put it in another function called mainGameLooop. and you are done

  1. Hi, i learned java. i started learning lwjgl with the with the aim to game development. i fell in love with lwjgl. Now i come to know that game engine( unity3d, udk etc) is required to develop games. A game engine abstracts out all of the OpenGL, low-level logic. It does 100% of the rendering for you (except for shaders). And developing a game engine is not one persons work. So why did/should i learn lwjgl? Now should i continue learning lwjgl? What are the advantages? Please reply at your earliest convenience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s