我已经开始学习 lwjgl 并且遇到了问题!我在做什么:
加载纹理
开始渲染周期
绘制矩形并应用纹理
检查键盘和鼠标事件并旋转/移动相机
public static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(320, 200)); Display.create(); } catch (Exception e) { System.out.println(e); } Texture texture = null; try { texture = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("basic.jpg"), true); } catch (Exception e) { System.out.println(e); return; } GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, 320, 0, 200, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); while (!Display.isCloseRequested()) { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); Color.white.bind(); texture.bind(); GL11.glBegin(GL11.GL_QUAD_STRIP); GL11.glTexCoord2f(0, 0); GL11.glVertex3f(100, 100, 0); GL11.glTexCoord2f(0, 1); GL11.glVertex3f(100, 140, 0); GL11.glTexCoord2f(1, 1); GL11.glVertex3f(140, 140, 0); GL11.glTexCoord2f(1, 0); GL11.glVertex3f(140, 100, 0); GL11.glEnd(); Display.update(); processInput(); try { //Thread.sleep(20); } catch (Exception e) { System.out.println(e); } } Display.destroy(); } public static void processInput() { long delta = getDelta(); long divider = 10000000; float camx = 0, camy = 0, camz = 0; float roll = 0; if (Keyboard.isKeyDown(Keyboard.KEY_W)) { camz += 1.0f * delta / divider; } if (Keyboard.isKeyDown(Keyboard.KEY_S)) { camz -= 1.0f * delta / divider; } if (Keyboard.isKeyDown(Keyboard.KEY_D)) { camx -= 1.0f * delta / divider; } if (Keyboard.isKeyDown(Keyboard.KEY_A)) { camx += 1.0f * delta / divider; } if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { camy -= 1.0f * delta / divider; } if (Keyboard.isKeyDown(Keyboard.KEY_C)) { camy += 1.0f * delta / divider; } if (Mouse.isButtonDown(0)) { roll += 1.0f * delta / divider; } if (Mouse.isButtonDown(1)) { roll -= 1.0f * delta / divider; } GL11.glTranslatef(camx, camy, camz); GL11.glTranslatef(160, 100, 0); GL11.glRotatef(roll, 0, 0, 1); GL11.glTranslatef(-160, -100, 0); }
当我在 XY 平面上旋转和移动所有东西时,它工作得很好。但是当我尝试沿 Z 轴移动时,整个矩形消失了。我做错了什么?