LWJGL在glDrawElements上崩溃

问题描述

我遇到了这个错误,我不知道可能是什么。 因此,iam激发了GLFW,创建了OpenGL功能,将Shader和VAO加载到VRAM中。

我真的不知道这会是什么。

[...acc,red]

着色器代码对于Moment而言非常简单。只是在这里回答任何问题就是《守则》。

basicmesh.vs

public static void main(String[] args){
        GLFWErrorCallback.createPrint(System.err).set();
        if(!glfwInit()) {
            assert false : "Failed to inialize GLFW";
        }
        
        glfwDefaultwindowHints();
        glfwWindowHint(GLFW_VISIBLE,GLFW_FALSE);
        glfwWindowHint(GLFW_RESIZABLE,GLFW_TRUE);
        
        long windowID = glfwCreateWindow(800,600,"title",NULL,NULL);
        if(windowID == NULL) {
            assert false : "Failed to create GLFW-Window";
        }
        
        glfwMakeContextCurrent(windowID);
        glfwSwapInterval(0);
        glfwShowWindow(windowID);
        GL.createCapabilities();
        
        
        
        Shader shader = new Shader(
                FileReader.readRaw("assets/shaders/basicmesh.vs"),FileReader.readRaw("assets/shaders/basicmesh.fs"));
        
        
        
        int vaoID = glGenVertexArrays();
        glBindVertexArray(vaoID);
        
        int vbo = glGenBuffers();
        glBindBuffer(GL_VERTEX_ARRAY,vbo);
        glBufferData(GL_VERTEX_ARRAY,new float[] {
                0.0f,0.0f,1.0f,0.0f
        },GL_STATIC_DRAW);
        
        glEnabLevertexAttribArray(0);
        glVertexAttribPointer(0,3,GL_FLOAT,false,0);
        
        glBindBuffer(GL_VERTEX_ARRAY,0);
        
        int ebo = glGenBuffers();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ebo);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER,new int[] {
                0,1,2,0
        },GL_STATIC_DRAW);
        
        glBindVertexArray(0);
        
        while(!glfwWindowShouldClose(windowID)) {
            
            glfwPollEvents();
            
            gluseProgram(shader.getID());
            
            glBindVertexArray(vaoID);
            //crahes here!!!
            glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0);
            
            glBindVertexArray(0);
            
            gluseProgram(0);
            
            glfwSwapBuffers(windowID);
            
        }
}

basicmesh.fs

#version 420 core

layout(location=0) in vec3 position;

void main() {
    gl_Position = vec4(position,1.0);
}

解决方法

GL_VERTEX_ARRAY不是有效的缓冲区绑定点,例如glBindBuffer。它崩溃的原因是因为您绑定了非法绑定点,所以未启用通用顶点属性0而未为其指定任何顶点数据。 glVertexAttribPointer寻找绑定到GL_ARRAY_BUFFER而不是GL_VERTEX_ARRAY的缓冲区。

您要绑定的对象不是GL_VERTEX_ARRAY,而是GL_ARRAY_BUFFER