LWJGL tutorial ( 2D Shoot 'Em Up)

Started by nicolasbol, February 21, 2008, 05:58:59

Previous topic - Next topic

nicolasbol

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

Fool Running

I got a crash when trying the webstart version:
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

wolf_m

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!

princec

Haha, worked for me, and it's very smooth and nicely done.

Cas :)

elias4444

I get the following error as well:
QuoteException 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

kappa

works for me too on my windows computer :)

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

nicolasbol

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 ;) !


ndhb

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.

Matzon

game linked to on documentations page (since its a tutorial)

Schnitter

There is "LWGSL" instead of "LWJGL" on the hompage ;)

But I love the game :)

Evil-Devil

Thx for sharing. Did you made all the textures yourself?

nicolasbol

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 ;) !

ndhb

The engine seems to work great. I have always liked shoot-em-ups :)

kappa

Got display problems here on linux with the error

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

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

createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, FULL_SCREEN) ;


and add this additional method to your tutorial

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.

nicolasbol

javalwjgl,

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

Hopefully it will fix the issue.

Thanks again ;) !