FPSAnimation不根据时间更新

时间:2015-02-07 14:32:22

标签: java animation jogl

我正在尝试学习JOGL,并且遵循这里的教程:https://sites.google.com/site/justinscsstuff/jogl-tutorial-3。一切似乎都要工作到最后,FPSAnimation对象似乎没有调用更新。我正在调整屏幕大小时会调用更新,但不会像我预期的那样每10秒调用一次。我确实需要对教程示例进行一些调整(Java抱怨说由于某些原因它无法将FPSAnimation转换为动画)。我在这里修改了代码:

public class SimpleScene implements GLEventListener {
    private double x = -1;
    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLCanvas canvas = new GLCanvas(caps);

        Frame frame = new Frame("Test");
        frame.setSize(300, 300);
        frame.add(canvas);
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        canvas.addGLEventListener(new SimpleScene());

        FPSAnimator animator = new FPSAnimator(canvas, 10);
        animator.add(canvas);
        animator.start();
    }

    public void display(GLAutoDrawable drawable) {
        update();
        render(drawable);
    }
    public void dispose(GLAutoDrawable drawable) {}
    public void init(GLAutoDrawable drawable) {}
    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {}

    private void update() {    x += 0.01;   }

    private void render(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glColor3f(1, 1, 1);
        gl.glVertex2d(-1, -1);  gl.glVertex2d(x, 1);  gl.glVertex2d(1, -1);
        gl.glEnd();
    }
}

我在Windows32上运行:

C:\Users\John>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

我已经在线查看,似乎无法找到对此问题的任何引用。任何帮助将不胜感激。

0 个答案:

没有答案