Newsletter:

(Tutorial) Java Games Tutorial: Getting Started With LWJGL

Tutorial: Java Games Tutorial: Getting Started With LWJGL

Welcome to the first tutorial on using the Lightweight Java Game Library created by these Java wizards.
A lot of work has gone into the library to effectively create an environment within the Java runtime capable of supporting high speed access to the display and input devices that games rely on.

As you may or may not know, Java runs in a self-contained virtual machine on a variety of operating systems and platforms. If your goal is to maximize platform support for your game, while at the same time minimizing the headaches due to crafting cross-platform code, then you would need some solid arguments for not choosing Java.

The reference section at the end of this tutorial has some other links which go into further details aimed at easing your fears about using Java for games.

The LWJGL Code
Before diving into working with OpenGL to draw objects using your hardware, there is some groundwork when dealing with LWJGL. For those not too familiar with the Lightweight Java Game Library, at a very loose level it can be thought of as a library for the Java Runtime, in the same vein as DirectX is a game library for Windows.

The whole point of LWJGL is to tuck away the unneccessary lower level display and input code, in order to provide you with the fastest possible access to these devices which games rely on.

Browsing through the project source code will provide a working example of what we are trying to accomplish with our tiny LWJGL framework, but I’ll try to explain the basic principles here.

The main workhorse of the sample, is the GameWindow object which is the kernel in our application and provides our Java entry point. In a lot of ways, the main use of LWJGL to get a basic game loop up and running is not really any different from our DirectX or SDL tutorials in C++.

try {
// find out what the current bits per pixel of the desktop is
int currentBpp = Display.getDisplayMode().getBitsPerPixel();

// find a display mode at 800x600
DisplayMode mode = findDisplayMode(800, 600, currentBpp);

// if can't find a mode, then bail!
if (mode == null) {
Sys.alert("Error", "800x600x" + currentBpp +
" display mode unavailable");
return;
}

// configure and create the LWJGL display
Display.setTitle("LWJGL-getting-started");
Display.setDisplayMode(mode);
Display.setFullscreen(false);

Display.create();

init();
} catch (LWJGLException e) {

e.printStackTrace();
Sys.alert("Error", "Failed: "+e.getMessage());

}

[Read More...]

Courtesy:- http://www.wazooinc.com/