2

我有这个我现在理解的代码:

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();
    }
}

我想知道如何绘制方框,使其不在屏幕上绘制,而是稍微退缩了一点,如何?

4

1 回答 1

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();

虽然这不会与正交中的单个四边形产生任何视觉差异。您必须切换到透视投影矩阵才能让它看起来像“移回”。

于 2013-03-05T20:28:16.173 回答