【发布时间】:2020-09-10 12:35:01
【问题描述】:
我遇到了这个错误,我不知道它可能是什么。 所以我正在初始化 GLFW,为 OpenGL 创建 Capability,将 Shader 和 VAO 加载到 VRAM 中。
我现在真的不知道会是什么。
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, 0.0f,
0.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
1.0f, 0.0f, 0.0f
}, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 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,
2,3,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.vs
#version 420 core
layout(location=0) in vec3 position;
void main() {
gl_Position = vec4(position, 1.0);
}
basicMesh.fs
#version 420 core
out vec4 color;
void main(){
color = vec4(1.0f, 1.0f, 0.0f, 1.0f);
}
【问题讨论】: