这是堆栈跟踪..
com.jogamp.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glEnableVertexAttribArray(<int> 0xFFFFFFFF): GL_INVALID_VALUE ( 1281 0x501),
at com.jogamp.opengl.DebugGL4bc.writeGLError(DebugGL4bc.java:30672)
at com.jogamp.opengl.DebugGL4bc.glEnableVertexAttribArray(DebugGL4bc.java:4921)
在object的draw()..
中float[] color = {1.0f, 0.0f, 0.0f, 1.0f};
// enable glsl
gl2.glUseProgram(shaderProgram);
// enable alpha
gl2.glEnable(GL.GL_BLEND);
gl2.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// Set color for drawing
setmColorHandle(gl2.glGetUniformLocation(shaderProgram, "vColor"));
gl2.glUniform4fv(getmColorHandle(), 1, color, 0);
// get handle to vertex shader's vPosition member
mPositionHandle = gl2.glGetAttribLocation(shaderProgram, "vPosition");
// Enable a handle to the triangle vertices
gl2.glEnableVertexAttribArray(mPositionHandle);
顶点着色器..
#version 120
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
片段着色器..
#version 120
uniform vec4 vColor;
void main() {
gl_FragColor = vColor;
}
答案 0 :(得分:3)
在顶点着色器中,您不会在任何地方使用vPosition
属性,因此驱动程序很可能在编译时将其优化掉。这意味着glGetAttribLocation
不会返回有效值,这意味着glEnableVertexAttribArray
将失败。更改顶点着色器以实际使用您声明的uMVPMatrix
和vPosition
变量,即:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
void main() {
gl_Position = uMVPMatrix * vPosition;
}
确保您实际传递了uMVPMatrix
的值(目前尚不清楚您是否会在代码中这样做)。