OpenGL "Invalid operation error" After glDrawElements function on android phone

I can't run my app on my phone, and I'v located the error, yet lack the knowledge in programming and in english to repair it. The app run's on emulator perfectly, without any errors in code neither in opengl. Yet on the phone everything runs fine without any errors, but show no opengl elements which i want to draw. I'v added `glGetError` almost everythere in my code, and found the error 1282 generated after `glDrawElements` which is `GL_INVALID_OPERATION`. `GL_INVALID_OPERATION` is generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped. `GL_INVALID_OPERATION` is generated if glDrawElements is executed between the execution of glBegin and the corresponding glEnd. I have no glBegin or glEnd in my code, so i guess the problem is in my indexbuffer. Below i present you everthing i have with the 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()); } Code of buffer in my object initialization function: 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); And that's basicaly everything i have done with this buffer. On surfaceCreated function >> 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); }
Can you post the code where you initialize OpenGL?

以上就是OpenGL "Invalid operation error" After glDrawElements function on android phone的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准