所以我想旋转对象,我调用 glPushMatrix() 来保存矩阵,glTranslatef 因为我希望对象有自己的轴,所以我将在屏幕中间移动对象,然后我做一个旋转,调用 glPopMatrix() 并没有任何反应:D
package Tanc;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.*;
public class Tanc{
public Tanc(){
try{
Display.setDisplayMode(new DisplayMode(640,480));
Display.setTitle("Tancc");
Display.create();
}catch(LWJGLException e){
e.printStackTrace();
}
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glOrtho(1, 1, 1, 1, 1, -1);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glMatrixMode(GL11.GL_PROJECTION);
float y_angle = 0;
while (!Display.isCloseRequested()) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
/*
GL11.glRectd(0, 0, 0.2f, 0.3f);
// GL11.glRotated(50, 1, 0, 0);
// GL11.glRotated(50, 0, 1, 0);
GL11.glRotated(1, 0, 0, 1);
// GL11.glTranslatef(0, 0, 0);
GL11.glTranslatef(-0.1f, -0.15f, 0);
// GL11.glTranslatef(-1f, -0.15f, 0);
GL11.glPopMatrix();
*/
GL11.glLoadIdentity();
GL11.glPushMatrix();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(0f, 0f);
GL11.glVertex2f(0.2f, 0f);
GL11.glVertex2f(0.2f, 0.3f);
GL11.glVertex2f(0f, 0.3f);
GL11.glEnd();
GL11.glTranslatef(-0.1f, -0.15f, 0);
GL11.glRotatef(30, 1, 0, 1);
GL11.glPopMatrix();
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
public static void main(String[] args){
new Tanc();
}
}