Hello Guest

LWJGL tutorial ( 2D Shoot 'Em Up)

  • 17 Replies
  • 31544 Views
LWJGL tutorial ( 2D Shoot 'Em Up)
« on: February 21, 2008, 05:58:59 »
Hello guys,

A while ago, I went through a famous shooter source code: Prototyp by X-Out and decided to see what I could do with my Java + OpenGL.
I remember I had a hard time starting with LWJGL, especially documentation.

Maybe this will help someone....or not ;) !

http://fabiensanglard.net/Prototyp/index.php

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #1 on: February 21, 2008, 19:32:15 »
I got a crash when trying the webstart version:
Code: [Select]
java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glEnable(GL11.java:884)
at rtype.Prototyp.initGL(Prototyp.java:347)
at rtype.Prototyp.<init>(Prototyp.java:137)
at rtype.Prototyp.main(Prototyp.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Other then that, it looks really nice 8)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #2 on: February 21, 2008, 19:47:32 »
Code: [Select]
java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glEnable(GL11.java:884)
at rtype.Prototyp.initGL(Prototyp.java:347)
at rtype.Prototyp.<init>(Prototyp.java:137)
at rtype.Prototyp.main(Prototyp.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
WinXP SP2, patched to hell and back, NVidia Geforce 7600 GT, 2 screens, 1280x1024 each, newest Java version.

Please fix, it looks very playable and I'm eager to try it!

*

Offline princec

  • *****
  • 1933
    • Puppygames
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #3 on: February 22, 2008, 00:41:05 »
Haha, worked for me, and it's very smooth and nicely done.

Cas :)

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #4 on: February 22, 2008, 04:16:50 »
I get the following error as well:
Quote
Exception in thread "javawsApplicationMain" java.lang.UnsatisfiedLinkError: /Users/eli/Library/Caches/Java/cache/javaws/http/Dfabiensanglard.net/P80/DMPrototyp/RNMON_native_mac.jar/liblwjgl.jnilib:
   at java.lang.ClassLoader$NativeLibrary.load(Native Method)
   at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
   at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1715)
   at java.lang.Runtime.loadLibrary0(Runtime.java:822)
   at java.lang.System.loadLibrary(System.java:993)
   at org.lwjgl.Sys$1.run(Sys.java:67)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.lwjgl.Sys.<clinit>(Sys.java:65)
   at org.lwjgl.util.Timer.<clinit>(Timer.java:50)
   at rtype.Prototyp.<clinit>(Prototyp.java:112)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at com.sun.javaws.Launcher.executeApplication(Launcher.java:1187)
   at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1125)
   at com.sun.javaws.Launcher.continueLaunch(Launcher.java:968)
   at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:522)
   at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:218)
   at com.sun.javaws.Launcher.run(Launcher.java:165)
   at java.lang.Thread.run(Thread.java:613)

I'm running Mac OS 10.5.2
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline kappa

  • *****
  • 1319
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #5 on: February 22, 2008, 13:44:11 »
works for me too on my windows computer :)

however didn't run on my linux system, same error as the post above.

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #6 on: February 22, 2008, 14:40:08 »
Thanks you very much for your feedback guys.

I can't spot the issue with the NullPointerException :(. I'll try harder today.
Regarding the Mac issue, I wonder if I an supposed to have a different set of library for Intel and G4 based CPU ?
Anyway, it's also a good opportunity to install Ubuntu, I'll try to fix it shortly.

Again thanks for taking the time to click ;) !


*

Offline ndhb

  • **
  • 70
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #7 on: February 22, 2008, 16:44:00 »
Heya.

I had the same problem as the others have reported. Turning on the Console Debug for Java, reveals that the exception is really:

java.lang.NullPointerException: mode must be non-null
   at org.lwjgl.opengl.Display.setDisplayMode(Display.java:223)
   at rtype.Prototyp.init(Prototyp.java:308)
   at rtype.Prototyp.<init>(Prototyp.java:136)
   at rtype.Prototyp.main(Prototyp.java:130)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.javaws.Launcher.executeApplication(Unknown Source)
   at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
   at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
   at com.sun.javaws.Launcher.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)

while the exception you get from clicking "Details" when the jnlp fails to run is:

java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glEnable(GL11.java:884)
   at rtype.Prototyp.initGL(Prototyp.java:347)
   at rtype.Prototyp.<init>(Prototyp.java:137)
   at rtype.Prototyp.main(Prototyp.java:130)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.javaws.Launcher.executeApplication(Unknown Source)
   at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
   at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
   at com.sun.javaws.Launcher.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


So the solution seems to be, to rewrite your selection of DisplayMode such that it is more thorough at selecting modes. With all the different GPUs and resolutions available, you probably want to try and go for something conservative like 800x600x32bpp.

I look forward to try your application when it's fixed.

*

Offline Matzon

  • *****
  • 2242
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #8 on: February 23, 2008, 15:26:46 »
game linked to on documentations page (since its a tutorial)

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #9 on: February 24, 2008, 08:05:43 »
There is "LWGSL" instead of "LWJGL" on the hompage ;)

But I love the game :)

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #10 on: February 25, 2008, 13:00:06 »
Thx for sharing. Did you made all the textures yourself?

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #11 on: February 27, 2008, 01:33:22 »
Guys,

ndhb: Thank you so much !, I couldn't reproduce the error !! I switched to 640x480, previous resolution was 640x400.

Matzon : Thanks for the link. I'm flattered.

Evil-Devil: No, the textures are from "Prototyp", the winner of the "Horizontal Shooter with Boss" competition. Only the "engine" is mine. I asked the author (X-Out) permission before using the textures and we granted me root access.

Schnitter: I fixed the typo, thanks for the feedback, very much appreciated ;) !

*

Offline ndhb

  • **
  • 70
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #12 on: February 27, 2008, 11:16:15 »
The engine seems to work great. I have always liked shoot-em-ups :)

*

Offline kappa

  • *****
  • 1319
Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #13 on: February 27, 2008, 22:01:13 »
Got display problems here on linux with the error

Code: [Select]
java.lang.NullPointerException: mode must be non-null
at org.lwjgl.opengl.Display.setDisplayMode(Display.java:223)
at rtype.Prototyp.init(Prototyp.java:308)
at rtype.Prototyp.<init>(Prototyp.java:136)
at rtype.Prototyp.main(Prototyp.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.javaws.Launcher.executeApplication(Launcher.java:1272)
at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1218)
at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1065)
at com.sun.javaws.Launcher.run(Launcher.java:105)
at java.lang.Thread.run(Thread.java:619)
#### Java Web Start Error:
#### null

I would recommend you replace this code as it will not work every where

Code: [Select]
DisplayMode displayMode = null;
       DisplayMode d[] = Display.getAvailableDisplayModes();
        for (int i = 0; i < d.length; i++) {
             if (d[i].getWidth() == SCREEN_WIDTH
                && d[i].getHeight() == SCREEN_HEIGHT
                && d[i].getBitsPerPixel() == 32) {
            displayMode = d[i];
break;
}
}
Display.setDisplayMode(displayMode);
Display.setFullscreen(FULL_SCREEN);
Display.create();

The following will work nicely for you

replace the code above with

Code: [Select]
createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, FULL_SCREEN) ;

and add this additional method to your tutorial

Code: [Select]
private void createWindow(int screenWidth, int screenHeight, boolean fullscreen) throws Exception {
   
    //enable frame sync with refresh rate
//Display.setVSyncEnabled(true);

   
    if (fullscreen) {
    Display.setFullscreen(true);
   
   
            try
            {
            DisplayMode dm[] = org.lwjgl.util.Display.getAvailableDisplayModes(320, 240, -1, -1, -1, -1, 60, 85);
                org.lwjgl.util.Display.setDisplayMode(dm, new String[] {
                    "width=" + screenWidth, "height=" + screenHeight, "freq=85",
                    "bpp=" + Display.getDisplayMode().getBitsPerPixel()
                });
            }
            catch(Exception e)
            {
                Log.warning("Could not start full screen, switching to windowed mode", e);
                Sys.alert("Error", "Could not start full screen, switching to windowed mode");
                Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
            }           
    }
   
    // else create windowed mode
    else {
    Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
    }
   
    // create display
        Display.create();
    }

hope it helps, should sort out the resolution problems you are having.

Re: LWJGL tutorial ( 2D Shoot 'Em Up)
« Reply #14 on: February 28, 2008, 04:12:45 »
javalwjgl,

I incorporated your suggestion in Java prototyp. I also set the default rendition to 800x600.

Hopefully it will fix the issue.

Thanks again ;) !