【问题标题】:LWJGL 3: OpenGL Quad is not rendered properlyLWJGL 3:​​OpenGL Quad 未正确渲染
【发布时间】:2017-05-24 22:30:50
【问题描述】:

每当我运行它时,都会弹出窗口并看到它。 (When I run the game, I see this)

如果您只是简单地创建一个新的 Java 项目,导入 OpenGL、GLFW 和 LWJGL 以及本机,然后复制代码(删除包),则可以重新创建它

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.GL;

public class Game {

    public static void main (String[] args) {

        if(glfwInit() != true) {
            System.err.println("GLFW Failed to initialize!");
            System.exit(1);
        }

        long window = glfwCreateWindow(640,480,"Game", 0, 0);

        glfwShowWindow(window);

        glfwMakeContextCurrent(window);
        GL.createCapabilities();

        while(!glfwWindowShouldClose(window)) {

            glfwPollEvents();

            glClear(GL_COLOR_BUFFER_BIT);

            glBegin(GL_QUADS);

            glVertex2d(-0.5,0.5);
            glVertex2d(0.5,0.5);
            glVertex2d(-0.5,-0.5);
            glVertex2d(0.5,-0.5);

            glEnd();

            glfwSwapBuffers(window);

        }

        glfwTerminate();

    }

}

【问题讨论】:

    标签: java opengl lwjgl glfw


    【解决方案1】:

    您以错误的顺序绘制四边形的顶点。试试

    glVertex2d(0.5,0.5);
    glVertex2d(-0.5,0.5);
    glVertex2d(-0.5,-0.5);
    glVertex2d(0.5,-0.5);
    

    对于面向您的四边形(或三角形)(这称为“缠绕”),您通常以逆时针顺序绘制它们,而对于背对您的四边形(或三角形),您通常以顺时针顺序绘制它们。在您的情况下,您将它们绘制成一个无效的字母“Z”。

    【讨论】:

    • 谢谢,这有帮助!我想我在想它会自动解决自己:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    相关资源
    最近更新 更多