LWJGL Window

By the end of this tutorial you will have learned how to create, update, and destroy a display compatible with the Lightweight Java Game Library.

Everything is static

Unlike in other Java windowing libraries, the LWJGL handles the window statically. Instead of creating an instance of the hypothetical Display class, static methods are invoked.

Importing classes

Note that Display refers to org.lwjgl.opengl.Display and not the other Display class. Also DisplayMode refers to org.lwjgl.opengl.DisplayMode. The methods that are used in this tutorials are listed below.

Display.setDisplayMode(DisplayMode);// Sets the display mode (width,height) of the window.
Display.setTitle(String);// Sets the window title to the specified String.
Display.create();// Creates a display with the specified display mode and title.
Display.isCloseRequested();// Returns if the user attempted to close the display.
Display.update();// Updates the contents of the display and checks for input.
Display.sync(int);// Caps the frame-rate of the display to the specified amount of frames-per-second.
Display.destroy();// Frees all the resources allocated for the display and destroys it.

Creating the LWJGL window

Since the method “Display.create()” throws an “LWJGLException”, the try-catch clause will resemble the following.

Destroying the LWJGL window

After the game loop has been broken, the resources have to be cleaned up. In this case of this program, the only thing that needs to be cleaned up in the display itself.

Display.destroy();

For some inexplicable reason the window does not immediately close when the user clicks on the close button – it lingers for several seconds. Fixing this consists of placing the following line after “Display.destroy();”.

System.exit(0);

This quits the Java Virtual Machine. Keep in mind that any code written after this will not be executed.

Post navigation

18 thoughts on “LWJGL Window”

On my Pc the program is running as it should but if I try to run it on my Laptop I get a Exception which says:”PixelFormat is not accellerated”
I already updated my graphic drivers but it still throws this Exception!
Please Help!!!

I am having a huge problem trying to create a game graphics engine from scratch without using any known libraries like jME or LWJGL, or J3D, etc. The reason why, is because I am a college student, and in Spring 2017, my professor will be teaching an exclusive Video Game Programming course for which I want to do a 3D video game.

I don’t know whether I am doing things wrong or right, but all my attempts at Backface removal, and collision detection, etc, you know the important things that make a game realistic, tend to come up wrong, or so I think, since I have not been really successful at it.

My professor taught the Video Game Programming course this past Spring 2015, for which I sat on the course the whole semester, and learned the basics. But he does not teach a complete 3D perspective of how to do a video game in 3D. The only things he showed us in 3D is, D*x/z and D*y/z and how draw a Cube.

You would probably say, my professor is not very good at 3D video game programming…And you are right. He is only expecting 2D, but I don’t want to do 2D. I want to learn 3D.

I found LWJGL library, and I found your videos on youtube, in which you mention that if one would want to be coached to see the video description. So I found your website, and now, I am trying to beg you to help me.

I don’t need to do a video game library from scratch the way the professor is expecting everyone to do in the class, but I would like to learn how to use LWJGL so I can build my video game from it.

Can you tell me what is a try – catch clause because I dont know what it is I only know basic java example if statements arithmetic loops (not all of them) arrays user input using scanner. Im learning it at school