lwjgl ライブラリのテクスチャをロードするために slick-util ライブラリを使用しています。3 つの「テクスチャ」変数 [topTex、sideTex、bottomTex] を作成し、それらに 3 つの異なる画像をロードしました。さまざまな可能性を見た後、何が問題なのかわかりません。変数のすべてで最後の画像を取得し続けます。
private static double WIDTH = 1920;
private static double HEIGHT = 1080;
private static double DEPTH = 1200;
private static double SPEED = 1;
private double posx = WIDTH / 2;
private double posy = HEIGHT / 2;
private double posz = DEPTH / 2;
private double rotx = 0;
private double roty = 0;
private double rotz = 0;
private Texture topTex;
private Texture sideTex;
private Texture bottomTex;
public static void main(String[] args) {
Program program = new Program();
program.start();
}
private void start() {
try {
if (WIDTH == Toolkit.getDefaultToolkit().getScreenSize().width && HEIGHT == Toolkit.getDefaultToolkit().getScreenSize().height) { Display.setFullscreen(true); }
else { Display.setDisplayMode(new DisplayMode((int)WIDTH, (int)HEIGHT)); }
Display.setTitle("LWJGL Minecraft Logo");
Display.create();
}
catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
this.initGL11();
this.loadTop();
this.loadSide();
this.loadBottom();
while (!Display.isCloseRequested()) {
this.pollInput();
this.render();
Display.update();
}
Display.destroy();
}
private void initGL11() {
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0, 0, (int)WIDTH, (int)HEIGHT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, WIDTH, HEIGHT, 0, 0, -DEPTH);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
}
private void loadTop() {
try {
topTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/topTex.png"));
}
catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
private void loadSide() {
try {
sideTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/sideTex.png"));
}
catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
private void loadBottom() {
try {
bottomTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/bottomTex.png"));
}
catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
private void pollInput() {
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { System.exit(0); }
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
posx = WIDTH / 2;
posy = HEIGHT / 2;
posz = DEPTH / 2;
rotx = 0;
roty = 0;
rotz = 0;
}
if (Keyboard.isKeyDown(Keyboard.KEY_W)) { posy = posy + SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_A)) { posx = posx - SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_S)) { posy = posy - SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_D)) { posx = posx + SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_Q)) { posz = posz - SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_E)) { posz = posz + SPEED; }
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { rotx = rotx + SPEED / 2; }
if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { roty = roty + SPEED / 2; }
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { rotz = rotz + SPEED / 2; }
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
Color.white.bind();
GL11.glPushMatrix();
GL11.glTranslated(posx, posy, posz);
GL11.glRotated(rotx, 1, 0, 0);
GL11.glRotated(roty, 0, 1, 0);
GL11.glRotated(rotz, 0, 0, 1);
GL11.glTranslated(-posx, -posy, -posz);
GL11.glBegin(GL11.GL_QUADS);
topTex.bind();
GL11.glTexCoord2d(0, 0);
GL11.glVertex3d(posx - 16, posy - 16, posz - 16);
GL11.glTexCoord2d(1, 0);
GL11.glVertex3d(posx + 16, posy - 16, posz - 16);
GL11.glTexCoord2d(1, 1);
GL11.glVertex3d(posx + 16, posy + 16, posz - 16);
GL11.glTexCoord2d(0, 1);
GL11.glVertex3d(posx - 16, posy + 16, posz - 16);
topTex.release();
sideTex.bind();
GL11.glTexCoord2d(0, 0);
GL11.glVertex3d(posx + 16, posy - 16, posz - 16);
GL11.glTexCoord2d(1, 0);
GL11.glVertex3d(posx + 16, posy - 16, posz + 16);
GL11.glTexCoord2d(1, 1);
GL11.glVertex3d(posx + 16, posy + 16, posz + 16);
GL11.glTexCoord2d(0, 1);
GL11.glVertex3d(posx + 16, posy + 16, posz - 16);
sideTex.release();
GL11.glEnd();
GL11.glPopMatrix();
}