Newbie Errors

Started by dangerdoc, February 11, 2012, 15:34:28

Previous topic - Next topic

dangerdoc

Hello, I am starting out a new project in LWJGL. From the description, you can tell I am new. I have a project in netbeans arranged like this:

Project/
     Package/
           main.java
           start.java
           load.java

The "load" part is what contains the lwjgl code. Here it is:

import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.openal.AL;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ResourceLoader;

public class load {
	
	private Audio oggEffect;
	
	private Audio wavEffect;
	
	private Audio aifEffect;
	
	private Audio oggStream;
	
	private Audio modStream;
	
	/**
	 * Start the test 
	 */
	public void load() {
		initGL(800,600);
		init();
		
		while (true) {
			update();
			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
			render();
			
			Display.update();
			Display.sync(100);

			if (Display.isCloseRequested()) {
				Display.destroy();
				AL.destroy();
				System.exit(0);
			}
		}
	}
	
	/**
	 * Initialise the GL display
	 * 
	 * @param width The width of the display
	 * @param height The height of the display
	 */
	private void initGL(int width, int height) {
		try {
			Display.setDisplayMode(new DisplayMode(width,height));
			Display.create();
			Display.setVSyncEnabled(true);
		} catch (LWJGLException e) {
			System.exit(0);
		}

		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glShadeModel(GL11.GL_SMOOTH);        
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		GL11.glDisable(GL11.GL_LIGHTING);                    
        
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
        GL11.glClearDepth(1);                                       
        
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        
        GL11.glViewport(0,0,width,height);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);

		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0, width, height, 0, 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
	}
	
    /**
    * Initialise resources
    */
    public void init() {

        try {
	    // you can play oggs by loading the complete thing into 
	    // a sound
	    oggEffect = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("testdata/restart.ogg"));
			
	    // or setting up a stream to read from. Note that the argument becomes
	    // a URL here so it can be reopened when the stream is complete. Probably
	    // should have reset the stream by thats not how the original stuff worked
	    oggStream = AudioLoader.getStreamingAudio("OGG", ResourceLoader.getResource("testdata/bongos.ogg"));
			
	    // can load mods (XM, MOD) using ibxm which is then played through OpenAL. MODs
	    // are always streamed based on the way IBXM works
	    modStream = AudioLoader.getStreamingAudio("MOD", ResourceLoader.getResource("testdata/SMB-X.XM"));

	    // playing as music uses that reserved source to play the sound. The first
	    // two arguments are pitch and gain, the boolean is whether to loop the content
	    modStream.playAsMusic(1.0f, 1.0f, true);
			
	    // you can play aifs by loading the complete thing into 
	    // a sound
	    aifEffect = AudioLoader.getAudio("AIF", ResourceLoader.getResourceAsStream("testdata/burp.aif"));

	    // you can play wavs by loading the complete thing into 
	    // a sound
	    wavEffect = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("testdata/cbrown01.wav"));
        } catch (IOException e) {
	}
    }
	
	/**
	 * Game loop update
	 */
	public void update() {
		while (Keyboard.next()) {
			if (Keyboard.getEventKeyState()) {
				if (Keyboard.getEventKey() == Keyboard.KEY_Q) {
					// play as a one off sound effect
					oggEffect.playAsSoundEffect(1.0f, 1.0f, false);
				}
				if (Keyboard.getEventKey() == Keyboard.KEY_W) {
					// replace the music thats curretly playing with 
					// the ogg
					oggStream.playAsMusic(1.0f, 1.0f, true);
				}
				if (Keyboard.getEventKey() == Keyboard.KEY_E) {
					// replace the music thats curretly playing with 
					// the mod
					modStream.playAsMusic(1.0f, 1.0f, true);
				}
				if (Keyboard.getEventKey() == Keyboard.KEY_R) {
					// play as a one off sound effect
					aifEffect.playAsSoundEffect(1.0f, 1.0f, false);
				}
				if (Keyboard.getEventKey() == Keyboard.KEY_T) {
					// play as a one off sound effect
					wavEffect.playAsSoundEffect(1.0f, 1.0f, false);
				}
			}
		}
		
		// polling is required to allow streaming to get a chance to
		// queue buffers.
		SoundStore.get().poll(0);
	}

	/**
	 * Game loop render
	 */
	public void render() {
		
	}
	
	/**
	 * Main method
	 */
	public static void main(String[] argv) {
		load soundExample = new load();
		soundExample.load();
	}
}


Is there a problem with the code? If not, is it the arrangement of the project? In the main class, there is the initializer. In start, a window that asks for startup options. Is there a way to get it to work? Here is the stacktrace:

run:
Sat Feb 11 10:33:32 EST 2012 INFO:Initialising sounds..
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
	at java.lang.Runtime.loadLibrary0(Runtime.java:823)
	at java.lang.System.loadLibrary(System.java:1028)
	at org.lwjgl.Sys$1.run(Sys.java:73)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
	at org.lwjgl.Sys.loadLibrary(Sys.java:95)
	at org.lwjgl.Sys.<clinit>(Sys.java:112)
	at org.lwjgl.openal.AL.<clinit>(AL.java:59)
	at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
	at org.newdawn.slick.openal.AudioLoader.init(AudioLoader.java:33)
	at org.newdawn.slick.openal.AudioLoader.getStreamingAudio(AudioLoader.java:73)
	at tffs.start.startgame(start.java:87)
	at tffs.start.actionPerformed(start.java:77)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.Component.processMouseEvent(Component.java:6288)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6053)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4651)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4481)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4481)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
	at java.awt.EventQueue.access$000(EventQueue.java:84)
	at java.awt.EventQueue$1.run(EventQueue.java:602)
	at java.awt.EventQueue$1.run(EventQueue.java:600)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$2.run(EventQueue.java:616)
	at java.awt.EventQueue$2.run(EventQueue.java:614)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Thanks in advance!
dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

dangerdoc

I am sorry for not providing enough information earlier, I was in a hurry. I am having a problem:

The lwjgl window will not even open.

Sorry for not providing enough info.

dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

Simon Felix

Download Cultris II, the fastest Tetris clone from http://gewaltig.net/

dangerdoc

I read this again, and I did everything right with setup. I can't even open a window for it. Does it need to be the main class? If so, is there a way to run it from another .jar?

Thanks,
dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

PinkieSwirl

It says that there is no lwjgl, so did you put something like this: -Djava.library.path=C:/LWJGL/lwjgl-2.8.2/native/windows under run and VM-Options in your project settings? As seen here: http://lwjgl.org/wiki/images/3/36/NetBeans10.png (from the wiki). Or did you add lwjgl to the project libs?

EDIT:
Or are you trying to run the jar outside netbeans?
Then look here: http://lwjgl.org/wiki/index.php?title=Distributing_Your_LWJGL_Application

EDIT2:
Just tested your code and it works for me, so you did not setup lwjgl correct!? Its a little bit confusing, because, what is your main class? what does start and main do? When i just run your load class, its all fine. What does the function startgame in start?

dangerdoc

So, basically,
I have LWJGL as a library with lwjgl.jar, jinput.jar, and jwjgl_util.jar, and, Slick as a library, with jogg.jar, and jorbis.jar. That Is what I did for library. I am trying just even to get it to run in Netbeans (no luck). My main and start classes contain code for a window that asks for settings, username, etc. Is the "-Djava.lib....." just pointing to the windows natives, so that it has to be in that location? Is it only optional? I only added the above mentioned .jar files under libs, and wrote the code. I think that when I get this figured out, I will be on the right track!  ;)

Thank you,
dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla

PinkieSwirl

For running it in netbeans you have it to say where the natives from lwjgl are. With "-Djava.library.path='path to your lwjgl natives for your system'" you show netbeans where this natives are. Thats why it is NOT optional. So it have to look something like this, asuming you downloaded the lwjgl-2.8.3.zip and use windows:

-Djava.library.path=C:/.../lwjgl-2.8.3/native/windows

When it is in your download directory:

-Djava.library.path=C:/Users/YourUserName/Downloads/lwjgl-2.8.3/native/windows

When there are spaces in your path name, you have to use quotes:

-Djava.library.path="C:/Users/Your User Name/Downloads/lwjgl-2.8.3/native/windows"

And that shows your stacktrace: "no lwjgl in java.library.path".

But this stands all in the wiki so ~

dangerdoc

All right, thanks! I think that solved my question!

Thank you!
dangerdoc
“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla