Help with LWJGL?

How is LWJGL different than JOGL? I know LWJGL is a game engine, but doesn’t Java already have support for input and things like that, so why even use a game engine (like LWJGL)? Isn’t that like reinventing the wheel? I would just like to know how LWJGL is so different than just using something else, such as JOGL. This is probably a really dumb question, but please bear with me. Thanks.

Edit: I can’t find too many tutorials, either. I’ve tried that NeHe website, but when I download all I get is a .jar fle.

LWJGL and JOGL were developed in parallel, so they both invented the wheel in the first time :slight_smile: JOGL is some more official, since sun is involved in the development and LWJGL is more community driven. JOGL is “only” an OpenGL binding, while LWJGL also adds sound and input processing not available in standard JRE, like Joystick support and a more direct input response.

There are other differences in window/fullscreen handling etc. and I think the majority of people here consider LWJGL more suited for games, while JOGL is more suited for integration in Desktop Apps like 3D-Editors or Visualization.

Thanks. But it’s kind of hard to find tutorials for LWJGL, seeing as how the wiki doesn’t really have tutorials on how to use LWJGL, and the information it does have just kind of makes you jump right in and doesn’t really explain things. And why not just use Java 3D or something like that?

this is pretty straightforward…
http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicopengl

the rest is just OpenGL …

jar files are just zipped (or pack2000) files, unzip with wathever compression software you are used to and ther you are

LWJGL and JOGL were developed in parallel, so they both invented the wheel in the first time[…]

LWJGL exists longer.

jar files are just zipped (or pack2000) files[…]

Jars are Zip files with an optional meta-inf/manifest.mf entry. The file extension for Pack200 (not 2000) is “pack”. It doesn’t make any sense to distribute files in that flavor, however. You either use GZip compression on top or a different compression scheme (and “pack” files are only a sub step if you take that route - otherwise it’s “pack.gz”).

So how do I turn a .jar file into something I can read and understand?

just extract it using a zipping program. You might have to rename the file to .zip

Or, on the console, type:


jar -xvf jarred_file.jar

Got a question: I’ve tried using lwjgl with both NetBeans and JCreator…but it’s not working. I followed the installation guides for both IDE’s(http://lwjgl.org/installation.php) but it’s still not working. Funny thing is that it has worked before, so I know I’m doing it right. I used this example to test lwjgl: http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicopengl

In JCreator I get the following error message:

--------------------Configuration: Space Invaders - j2sdk1.4.2_15 <Default> - <Default>--------------------
java.lang.NoClassDefFoundError: Game (wrong name: game)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main" 
Process completed.

and in NetBeans IDE 5.0:


init:

deps-jar:

Compiling 1 source file to C:\Documents and Settings\eng06itara\Game\build\classes

compile:

run:

java.lang.NoClassDefFoundError: C:\Documents

Exception in thread "main" 

Java Result: 1

BUILD SUCCESSFUL (total time: 3 seconds)


And yes, I have entered the correct path to lwljgl1.1.2(C:\Documents and Settings\eng06itara\Skrivbord\lwjgl-1.1.2\lwjgl-1.1.2)

Please help me :slight_smile:

I haven’t used NetBeans or JCreator, but I have seen errors like those before…

The first error is a classpath issue and so if you can find a way to configure the classpath for the java command that is used to run the code, I think it may resolve the issue.

The second error looks like it has to do with a file path that uses spaces. Notice how the error message cut off the path right after C:\Documents? If you can quote the path, as in…
java -classpath “C:\Documents and Settings\eng06itara\Game\build\classes” (full name of class w/package), it should work.

As I said, I haven’t used those IDEs and so hopefully someone can answer for those specifically, but I thought these suggestions might help you.

Now I get the following message in JCreator:


java.lang.NoClassDefFoundError
    at Game.cleanup(Game.java:105)
    at Game.main(Game.java:40)
Exception in thread "main" 
Process completed.
 

here’s the code:


import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
 
/**
 * Basic game
 *
 * @author Name <email>
 * @version 1.0
 */
public class Game {
 
  /** Game title */
  public static final String GAME_TITLE = "My Game";
 
  /** Desired frame time */
  private static final int FRAMERATE = 60;
 
  /** Exit the game */
  private static boolean finished;
 
  /** Angle of rotating square */
  private static float angle;
 
  /**
   * Application init
   * @param args Commandline args
   */
  public static void main(String[] args) {
    boolean fullscreen = (args.length == 1 && args[0].equals("-fullscreen"));
 
    try {
      init(fullscreen);
      run();
    } catch (Exception e) {
      e.printStackTrace(System.err);
      Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
    } finally {
      cleanup();
    }
    System.exit(0);
  }
 
  /**
   * Initialise the game
   * @throws Exception if init fails
   */
  private static void init(boolean fullscreen) throws Exception {
    // Create a fullscreen window with 1:1 orthographic 2D projection (default)
    Display.setTitle(GAME_TITLE);
    Display.setFullscreen(fullscreen);
 
    // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
    Display.setVSyncEnabled(true);
 
    // Create default display of 640x480
    Display.create();
  }
 
  /**
   * Runs the game (the "main loop")
   */
  private static void run() {
 
    while (!finished) {
      // Always call Window.update(), all the time - it does some behind the
      // scenes work, and also displays the rendered output
      Display.update();
 
      // Check for close requests
      if (Display.isCloseRequested()) {
	finished = true;
      } 
 
      // The window is in the foreground, so we should play the game
      else if (Display.isActive()) {
        logic();
        render();
        Display.sync(FRAMERATE);
      } 
 
      // The window is not in the foreground, so we can allow other stuff to run and
      // infrequently update
      else {
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        logic();
 
	// Only bother rendering if the window is visible or dirty
        if (Display.isVisible() || Display.isDirty()) {
          render();
        }
      }
    }
  }
 
  /**
   * Do any game-specific cleanup
   */
  private static void cleanup() {
    // Close the window
    Display.destroy();
  }
 
  /**
   * Do all calculations, handle input, etc.
   */
  private static void logic() {
    // Example input handler: we'll check for the ESC key and finish the game instantly when it's pressed
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
      finished = true;
    }
 
    // Rotate the square
    angle += 2.0f % 360;
  }
    /**
   * Render the current frame
   */
  private static void render() {
    // clear the screen
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
 
    // center square according to screen size
    GL11.glPushMatrix();
    GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
 
      // rotate square according to angle
      GL11.glRotatef(angle, 0, 0, 1.0f);
 
      // render the square
      GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2i(-50, -50);
        GL11.glVertex2i(50, -50);
        GL11.glVertex2i(50, 50);
        GL11.glVertex2i(-50, 50);
      GL11.glEnd();
 
    GL11.glPopMatrix();
  }
}


Maybe i should just try to re-install everything and clean up the mess it has turned into and then give it another try :-\

You simply don’t have the lwjgl.jar in your runtime classpath; and/or the lwjgl.dll, which needs to be pointed at with -Djava.library.path

Cas :slight_smile:

Okay…I tried that command -Djava… and the window creation worked. Then I tried compiling the openGL-test from the cmd, but I got errors. All of them because org.lwjgl.* wasn’t found. What do I do now?

btw, gonna try to get it working with JCreator and Netbeans within 2 hours.

It’s working now :slight_smile: In Netbeans. Good thing, cause I don’t like JCreator :wink: