public void onDrawFrame(GL10 gl10, boolean fpsTimeElapsed) { GL11 gl = (GL11) gl10; updateWithDelta(1.0f / MAXIMUM_UPDATE_RATE); synchronized (transforms) { if (fpsTimeElapsed) { onTransform(); } } sourcePosition.x = x; sourcePosition.y = y; gl.glMatrixMode(GL11.GL_MODELVIEW); gl.glLoadIdentity(); gl.glEnableClientState(GL11.GL_COLOR_ARRAY); // unbind all buffers gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0); gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); gl.glBindTexture(GL11.GL_TEXTURE_2D, 0); gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesID[0]); // Using glBufferSubData means that a copy is done from the quads array to the buffer rather // than recreating the buffer which // would be an allocation and copy. The copy also only takes over the number of live particles. // This provides a nice performance // boost. quadsBuffer.put(quads); quadsBuffer.position(0); gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, 0, 128 * particleIndex, quadsBuffer); // Configure the vertex pointer which will use the currently bound VBO for its data gl.glVertexPointer(2, GL11.GL_FLOAT, 32, 0); gl.glColorPointer(4, GL11.GL_FLOAT, 32, (4 * 4)); gl.glTexCoordPointer(2, GL11.GL_FLOAT, 32, (4 * 2)); if (hasTexture) { gl.glEnable(GL11.GL_TEXTURE_2D); gl.glBindTexture(GL11.GL_TEXTURE_2D, getTexture().getTextureId()); } gl.glBlendFunc(srcBlendFactor, dstBlendFactor); gl.glDrawElements(GL11.GL_TRIANGLES, particleIndex * 6, GL11.GL_UNSIGNED_SHORT, indicesBuffer); gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); gl.glDisableClientState(GL11.GL_COLOR_ARRAY); }
public GLState(GL11 gl) { mGL = gl; // Disable unused state gl.glDisable(GL11.GL_LIGHTING); // Enable used features gl.glEnable(GL11.GL_DITHER); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glEnable(GL11.GL_TEXTURE_2D); gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); // Set the background color gl.glClearColor(0f, 0f, 0f, 0f); gl.glClearStencil(0); gl.glEnable(GL11.GL_BLEND); gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); // We use 565 or 8888 format, so set the alignment to 2 bytes/pixel. gl.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 2); }