我浏览了解决方案,但还没有真正找到。我收到此错误是因为执行似乎发生在 gl 线程之外。但是我不确定如何解决这个问题。代码如下:
public shape()
{
super();
vertexShader = Shader.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); //<============
fragmentShader = Shader.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
ByteBuffer buffer = ByteBuffer.allocateDirect(getCoordinates().length * 4);
buffer.order(ByteOrder.nativeOrder());
vertexBuffer = buffer.asFloatBuffer();
vertexBuffer.put(getCoordinates());
vertexBuffer.position(0);
ByteBuffer drawListBuffer = ByteBuffer.allocateDirect(getOrderOfDraw().length * 2);
drawListBuffer.order(ByteOrder.nativeOrder());
listBuffer = drawListBuffer.asShortBuffer();
listBuffer.put(getOrderOfDraw());
listBuffer.position(0);
mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
GLES20.glLinkProgram(mProgram);
}
调用渲染器是
Square square = new Square(5, 5);
public void onDrawFrame(GL10 unused)
{
unused.glLoadIdentity();
unused.glClear(GLES20.GL_COLOR_BUFFER_BIT);
square.Draw();
}
正方形从形状延伸