场景中的OpenGL LWJGL3对象不会旋转

时间:2014-12-15 00:19:53

标签: java opengl lwjgl

我正在尝试学习如何在LWJGL3中使用OpenGL,但是,我在早期的障碍中做得不够。我已经设置了场景,因此它渲染了半个八面体,每个面都有不同的颜色可以区分。我有这个代码来创建形状:

    private void drawOctohedron() {
    glPushMatrix();
    glRotatef((float)glfwGetTime() * 60,0f,1f,0f);
    System.out.println(glfwGetTime());
    glBegin(GL_TRIANGLES); {
        glColor4f(1.0F, 0.0F, 0.0F, 1.0F);
        glVertex3i(0, 1, 0);
        glVertex3i(-1, 0, 0);
        glVertex3i(0, 0, 1);
        glNormal3i(-1, 1, 1);

        glColor4f(0.0F, 1.0F, 0.0F, 1.0F);
        glVertex3i(0, 1, 0);
        glVertex3i(0, 0, 1);
        glVertex3i(1, 0, 0);
        glNormal3i(1, 1, 1);

        glColor4f(0.0F, 0.0F, 1.0F, 1.0F);
        glVertex3i(0, 1, 0);
        glVertex3i(1, 0, 0);
        glVertex3i(0, 0, -1);
        glNormal3i(1, 1, -1);

        glColor4f(1.0F, 0.0F, 1.0F, 1.0F);
        glVertex3i(0, 1, 0);
        glVertex3i(0, 0, -1);
        glVertex3i(-1, 0, 0);
        glNormal3i(-1, 1, -1);
    }
    glPopMatrix();
}

这就是循环:

    private void loop() {
    // This line is critical for LWJGL's interoperation with GLFW's
    // OpenGL context, or any context that is managed externally.
    // LWJGL detects the context that is current in the current thread,
    // creates the ContextCapabilities instance and makes the OpenGL
    // bindings available for use.
    GLContext.createFromCurrent();

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    while ( glfwWindowShouldClose(window) == GL_FALSE ) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glfwPollEvents();

        glMatrixMode(GL_MODELVIEW);

        glLoadIdentity();

        camera.lookThrough();

        drawOctohedron();

        glFlush();

        System.out.println("UPS: " + 1/(glfwGetTime() - lastTime));

        lastTime = glfwGetTime();

        glfwSwapBuffers(window);
    }

    System.out.println("Closing");

}

形状对显示器呈现精细但旋转仅发生一次。每个tick都调用该方法,System.out行每个tick都打印一个不同的值。我的问题是,为什么轮换只发生一次而不是在下次调用该方法时更新?我可能只是对一件小事非常愚蠢。

0 个答案:

没有答案