I can not run my application on my phone, and I found an error, but I do not have enough knowledge in programming and in English to restore it. The application works on the emulator perfectly, without errors in the code and in opengl. However, on the phone everything works fine without errors, but does not display the opengl elements that I want to draw. I added glGetError
almost everything in my code and found a 1282 error generated after glDrawElements
, which is GL_INVALID_OPERATION
.
GL_INVALID_OPERATION
generated if a nonzero name of the buffer object is GL_INVALID_OPERATION
to the included array or array of elements, and the data object storage of the buffer object is currently displayed.
GL_INVALID_OPERATION
generated if glDrawElements is executed between the execution of glBegin and the corresponding glEnd.
I don't have glBegin or glEnd code in my code, so I think the problem is in my indexbuffer. Below I present to you everything that I have with 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()); }
Buffer code in my object initialization:
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 basically all Iβve done with this buffer.
On the surface Function created β
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); }