我有以下代码:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class GameManager {
static int DEFAULT_DISPLAY_WIDTH = 855;
static int DEFAULT_DISPLAY_HEIGHT = 485;
public void startGame()
{
startGame("Unnamed Game");
}
public void startGame(String gameTitle)
{
new EventGameStart().run();
try {
Display.setTitle(gameTitle);
Display.setDisplayMode(new DisplayMode(DEFAULT_DISPLAY_WIDTH,
DEFAULT_DISPLAY_HEIGHT));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
new GameLoader().load();
Texture texture = null;
try {
texture = TextureLoader.getTexture("PNG", new FileInputStream("resources/ball.png"), true);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while (!Display.isCloseRequested()) {
while (Keyboard.next()) {
if (Keyboard.getEventKey() == Keyboard.KEY_F11
&& Keyboard.getEventKeyState()) {
new EventFullscreen().run();
}
if (Keyboard.getEventKey() == Keyboard.KEY_F12
&& Keyboard.getEventKeyState()) {
new EventScreenshot().run();
}
}
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(0, 0);
GL11.glVertex2f(0 + 200, 0);
GL11.glVertex2f(0 + 200, 0 + 200);
GL11.glVertex2f(0, 0 + 200);
GL11.glEnd();
Display.update();
}
new EventGameClose().run();
Display.destroy();
}
}
和 GameLoader():
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
/** Loads the game... */
public class GameLoader extends GameManager {
/** Called by GameManager */
public void load() {
setUpOpenGL();
}
/** Loading the OpenGL Settings */
private void setUpOpenGL()
{
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
}
但是如果我启动脚本,我只会看到一个黑色窗口:(。我不知道我应该做什么。我包含的包如下:
-lwjgl.jar
-lwjgl_util.jar
-slick-util.jar
任何想法?感谢:D