我现在已经理解了这段代码:
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class Main {
public void start() {
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
// init OpenGL
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 0, 600, 0, 800);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
while (!Display.isCloseRequested()) {
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
// set the color of the quad (R,G,B,A)
GL11.glColor3f(1.0f,1.0f,1.0f);
// draw quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(100,100);
GL11.glVertex2f(100+200,100);
GL11.glVertex2f(100+200,100+200);
GL11.glVertex2f(100,100+200);
GL11.glEnd();
Display.update();
}
Display.destroy();
}
public static void main(String[] argv) {
Main quadExample = new Main();
quadExample.start();
}
}
我想知道如何绘制方框,以便它不会在屏幕上绘制,但有点挫折,怎么样?
答案 0 :(得分:1)
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex3f(100,100,-100);
GL11.glVertex3f(100+200,100,-100);
GL11.glVertex3f(100+200,100+200,-100);
GL11.glVertex3f(100,100+200,-100);
GL11.glEnd();
虽然这不会与正交中的单个四边形产生任何视觉差异。您必须切换到透视投影矩阵,使其看起来像“向后移动”。