0
Когда я пытаюсь привязать текстуру к сфере в LWJGL, окно не отвечает в течение примерно 30 секунд. Появится сообщение об ошибке. Я попытался добавить больше места в java, но он все еще не работал. Это код для сферы и текстур:LWJGL - texture.bind не хватает места
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND);
Texture earthTexture = TextureLoader.getTexture("JPG",
ResourceLoader.getResourceAsStream(earthPath));
//enable and bind the texture
earthTexture.bind();
Sphere earth = new Sphere();
earth.setDrawStyle(GLU.GLU_FILL);
earth.setTextureFlag(true);
earth.setNormals(GLU.GLU_SMOOTH);
earth.draw(2.3f, 25, 25);
Это полный класс:
package com.game.planets;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.Sphere;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class EarthPlanet {
public static String earthPath = "src/com/game/planets/textures/earth.jpg";
static Texture earthTexture;
public static void renderEarth(){
earthTexture = loadTexture("earth");
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
earthTexture.bind();
Sphere earth = new Sphere();
earth.setDrawStyle(GLU.GLU_FILL);
earth.setTextureFlag(true);
earth.setNormals(GLU.GLU_SMOOTH);
earth.draw(2.3f, 25, 25);
earthTexture.release();
}
private static Texture loadTexture(String key){
try {
return TextureLoader.getTexture("JPG",
new FileInputStream(new File("src/com/game/planets/textures/" + key+ ".jpg")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
Как я могу это сделать? –
@ D.White добавил код в мой ответ – Reinard
Он дал мне эту ошибку: Исключение в потоке «главный» java.lang.NullPointerException \t в com.game.main.GameWindow.gameLoop (GameWindow.java:108) \t в com.game.main.GameWindow.main (GameWindow.java:31) –