上glDrawElements功能,我不能在我的手機上運行我的應用程序,和我心中已經位於錯誤,但缺乏編程知識和英語進行修復。 該應用程序在模擬器上完美運行,在代碼中沒有任何錯誤,在opengl中都沒有。然而,在手機上,一切運行良好,沒有任何錯誤,但沒有顯示我想繪製的opengl元素。我在代碼中幾乎添加了glGetError
,並且發現在glDrawElements
之後生成的錯誤1282是GL_INVALID_OPERATION
。OpenGL的「無效的操作錯誤」後,Android手機
GL_INVALID_OPERATION
是在非零緩衝區對象名稱綁定到已啓用數組 或當前映射元素數組和緩衝區對象的數據存儲區時生成的。
GL_INVALID_OPERATION
如果在執行glBegin和相應的glEnd之間執行glDrawElements,則執行 。
我在我的代碼沒有在glBegin和glEnd,所以我想這個問題是在我的indexbuffer。下面我給你介紹一下你的指數緩衝器。在我的對象初始化函數緩衝的
private ShortBuffer _indexBuffer;
public void onDrawFrame(GL10 gl) {
FramesPerSecond.StartCounter();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
for (int i = 1; i <= 10; i++) {
gl.glLoadIdentity();
gl.glTranslatef(0.0f, -1f, -1.0f + -1.5f * i);
gl.glRotatef(-_xAngle, 1f, 0f, 0f);
gl.glRotatef(-_yAngle, 0f, 1f, 0f);
gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);
Log.e("Warning", " error code " +gl.glGetError());
}
代碼:
short[] indeksai = new short[] {
0, 1, 3,
0, 2, 1,
0, 3, 2,
1, 2, 3,
};
ByteBuffer ibb = ByteBuffer.allocateDirect(indeksai.length * 2);
ibb.order(ByteOrder.nativeOrder());
_indexBuffer = ibb.asShortBuffer();
_indexBuffer.put(indeksai);
而這一切basicaly我有這個緩衝完成。
在surfaceCreated功能>>
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Log.i(LOG_TAG, "onSurfaceCreated()");
gl.glMatrixMode(GL10.GL_PROJECTION);
float ratio = _width/_height;
gl.glOrthof(-1, 1, -1/ratio, 1/ratio, 0.01f, 100.0f);
gl.glViewport(0, 0, (int) _width, (int) _height);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glClearColor(0f, 0f, 0f, 1.0f);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glFrontFace(GL10.GL_CCW);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
initTriangle(gl, context);
try {
loadGLTexture(gl);
} catch (IOException e) {
Log.w(LOG_TAG, "Texture fail");
}
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
你可以在初始化OpenGL的地方發佈代碼嗎? – CaseyB
我添加了onSurfaceCreated函數,我猜這是你要求的:)? – Datenshi
誰調用'onDrawFrame()'? –