我正在創建一個應用程序,它將讀取stl文件並使用OpenGL ES 2.0顯示它們。我已經成功顯示硬編碼的三角形,並將其添加到onSurfaceCreated()方法中的三角形列表中。我遇到的問題是當我嘗試從stl文件填充我的三角形對象列表並繪製它們時。最好我可以告訴,頂點的座標都是有效的,並在適當的格式。我總是得到主題錯誤。我在調試這個問題時遇到了麻煩,不知道該怎麼做。以下是三角形課程中發生問題的部分代碼。具體錯誤是在代碼行OpenGL ES 2.0崩潰(glGetUniformLocation:glError 1281)
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
MyRenderer.checkGlError("glGetUniformLocation");
public void draw(float[] mvpMatrix) {
// Add program to OpenGL environment
GLES20.glUseProgram(mProgram);
// get handle to vertex shader's vPosition member
mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
// Enable a handle to the facet vertices
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Prepare the triangle coordinate data
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
vertexStride, vertexBuffer);
// get handle to fragment shader's vColor member
mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
// Set color for drawing the facet
GLES20.glUniform4fv(mColorHandle, 1, color, 0);
// get handle to shape's transformation matrix
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
MyRenderer.checkGlError("glGetUniformLocation");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
MyRenderer.checkGlError("glUniformMatrix4fv");
// Draw the facet
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
//If edge mode
//GLES20.glUniform4fv(mColorHandle, 1, edgeColor, 0);
//GLES20.glLineWidth(2.0f);
//GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, vertexCount);
// Disable vertex array
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
有關如何調試這種情況的任何想法?另外,我還不清楚添加/刪除程序執行過程中要繪製的對象的最佳方法。我的想法是保持對象列表並在onDraw中循環遍歷它們嗎?