为了账号安全,请及时绑定邮箱和手机立即绑定

尝试用 LWJGL3 绘制基本形状

尝试用 LWJGL3 绘制基本形状

慕容708150 2021-06-01 10:12:42
所以我想使用 VAO 和 VBO 绘制一个形状,我认为我做的一切都是正确的,但是每当我运行我的代码时,我都会得到带有清晰颜色的窗口。在调用创建功能之前尝试初始化三角形时,我遇到了一个问题,我是否缺少一些开始绘图的函数?这是我的代码:int vaoId, vboId, vertexCount;float[] vertices = {    // Left bottom triangle    -0.5f, 0.5f,    -0.5f, -0.5f,    0.5f, -0.5f,};private void init() {    if (!glfwInit()) {        throw new IllegalStateException("Failed to Initialize GLFW!");    }    int width = 1000;    int height = 1000;    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);    window = glfwCreateWindow(width, height, "App", NULL, NULL);    if (window == 0) {        throw new IllegalStateException("Failed to create Window!");    }    GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());    glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2);    // Make the OpenGL context current    glfwMakeContextCurrent(window);    // Enable v-sync    glfwSwapInterval(1);    glfwShowWindow(window);}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 GLCapabilities instance and makes the OpenGL    // bindings available for use.    GL.createCapabilities();    initTriangle();    // Run the rendering loop until the user has attempted to close    // the window or has pressed the ESCAPE key.    while (!glfwWindowShouldClose(window)) {        glClear(GL_COLOR_BUFFER_BIT); // clear the framebuffer        glBindVertexArray(vaoId);        glEnableVertexAttribArray(0);        glDrawArrays(GL_TRIANGLES, 0, vertexCount);        glDisableVertexAttribArray(0);        glBindVertexArray(0);        glfwSwapBuffers(window); // swap the color buffers        // Poll for window events. The key callback above will only be        // invoked during this call.        glfwPollEvents();    }}希望大家帮帮忙,万分感谢。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 224 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信