LWJGL, Newbie Questions Regarding... Many Things... (Multiple Questions)

Started by WillSmith190, December 14, 2010, 17:24:38

Previous topic - Next topic

WillSmith190

So here, I'm just going to start a topic regarding questions I have, but are not worth another topic. Just scroll through until you find an unsolved one you can solve, or, if you got here from a search, see if you can find a solution that fits your needs.



Index:
Question #1: Solved
Question/Problem #2: Unsolved



Question #1 [Solved]

Hi, I'm new to LWJGL and still new to Java (but Eclipse's setup makes it very easy to program, and I know other Java-like languages) and I have some questions regarding the project setup. I'm making an skeleton game that I will copy and use for other games in the, basicly a game engine. I need some help on how to setup my project. This is how its setup:

Root
  >>src
     >>engine
        >>engine files
     >>game
        >>base game files
 
I've got everything working, but I don't know where to put resources like images, sounds, etc. I also need to know where to put XML property files. And then, how to access them. If I do a link from a java file in 'engine' that says 'res/img/foo.png' it will look in 'engine/res/img/foo.png' but thats weird place to put it. So, how would I do a link from the projects root?




Question/Problem #2

Well, I can't get OpenGL to work. Do I need to initilize it? This is what I'm doing:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, mode.getWidth(), 0, mode.getHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, mode.getWidth(), mode.getHeight());
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


There are no errors, but it crashes during runtime (I think). It says this:

Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2052)
   at engine.engine_window.setupOpenGL(engine_window.java:41)
   at Game.GameApplet.main(GameApplet.java:150)

Do I need some other stuff to make it work properly?


Thanks :)

broumbroum


WillSmith190

Quote from: broumbroum on December 14, 2010, 17:40:48
Use the '/' slash! :)

So, like "/res/img/foo,png"? I'll try that. It seems to very different in some other languages, so I was confused...

Edit:

Ah, yes that works! Sorry if I seem silly with my questions, but all my silly mistakes I will learn from.

Orangy Tang

Quote from: WillSmith190 on December 14, 2010, 17:24:38
Well, I can't get OpenGL to work. Do I need to initilize it? This is what I'm doing:
Have you created a display before you start calling OpenGL functions? (look at the sample code for some hints).

Matthias

Don't use absolute paths (with a starting '/') using getResource. Some class loaders implement this wrong.

The best way to handle that is to put a dummy class at the root of the resources and to let the application code call getResource and pass in the URL.
As an alternative the application code could pass the dummy class to your engine, then the engine can use this Class<?> to call getResource.

Also important thing is: You can't access resources in different JAR files or different build directories using relative paths with getResource.
In this case you should use several dummy classes as above.

It may work where you locally test - but if it will work when deployed depends on many things like security settings, the used JRE version etc.