Hello everyone!
I have a problem with creating my skybox. I load it with the following code:
/**
* Generates a skybox from six files (North,South,West,East,Down,Up).<br>
* Example: location=<i>data/textures/skybox1.jpg</i><br>
* For this location the following textures will be used for creating the skybox:<br>
* <i>skybox1_north.jpg, skybox1_south.jpg, skybox1_west.jpg, ...</i>
*
* @param location filename giving dir and format of the skybox textures
* @return a valid skybox or null
*/
public static Skybox getSkybox(String location) {
String parts1[] = location.split("/");
String filename = parts1[parts1.length-1];
int dotPos = filename.lastIndexOf(".");
int slashPos = location.lastIndexOf("/");
String dir = location.substring(0,slashPos+1);
String name = filename.substring(0, dotPos);
String type = filename.substring(dotPos);
Skybox skybox = new Skybox("Skybox "+name, 500, 500, 500);
skybox.setTexture(Skybox.NORTH, getTextureFromFile(dir+name+"_north"+type));
skybox.setTexture(Skybox.SOUTH, getTextureFromFile(dir+name+"_south"+type));
skybox.setTexture(Skybox.WEST, getTextureFromFile(dir+name+"_west"+type));
skybox.setTexture(Skybox.EAST, getTextureFromFile(dir+name+"_east"+type));
skybox.setTexture(Skybox.DOWN, getTextureFromFile(dir+name+"_down"+type));
skybox.setTexture(Skybox.UP, getTextureFromFile(dir+name+"_up"+type));
skybox.preloadTextures();
skybox.updateRenderState();
return skybox;
}
The method getTextureFromFile does nothing more than to call TextureManager.loadTexture with a bit of exception handling and stuff.
If i load the textures for each side seperately i they work (i can put them to RenderStates and apply them to any object).
However, preloadTextures causes an exception:
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glHint(GL11.java:1508)
at com.jme.scene.state.lwjgl.LWJGLTextureState.apply(LWJGLTextureState.java:418)
at com.jme.scene.Skybox.preloadTextures(Skybox.java:271)
at de.spacemonkeys.util.Util.getSkybox(Util.java:107)
at de.spacemonkeys.Demo.<init>(Demo.java:37)
at de.spacemonkeys.Main.main(Main.java:31)
I see where the problem is, but don't understand why it is there. Can anyone help?