Exemple #1
0
  public void render(GL10 gl, Texture texture) {
    gl.glEnable(GL10.GL_TEXTURE_2D);
    texture.bind(gl);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    GL11 gl11 = (GL11) gl;
    // draw using hardware buffers
    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexbufferId);
    gl11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);

    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, texturebufferId);
    gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexbufferId);
    gl11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_SHORT, 0);

    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    //		if (vertexbufferId == 0 || texturebufferId == 0 || indexbufferId == 0 || gl11.glGetError()
    // != 0) {
    //			Log.e("Grid", "VBO Not available: " + gl11.glGetError() + ", " +
    // gl11.glGetString(gl11.glGetError()));
    //		}
  }
  public void drawMesh(
      BasicTexture tex, int x, int y, int xyBuffer, int uvBuffer, int indexBuffer, int indexCount) {
    float alpha = mAlpha;
    if (!bindTexture(tex)) return;

    mGLState.setBlendEnabled(mBlendEnabled && (!tex.isOpaque() || alpha < OPAQUE_ALPHA));
    mGLState.setTextureAlpha(alpha);

    // Reset the texture matrix. We will set our own texture coordinates
    // below.
    setTextureCoords(0, 0, 1, 1);

    saveTransform();
    translate(x, y);

    mGL.glLoadMatrixf(mMatrixValues, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, xyBuffer);
    mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, uvBuffer);
    mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    mGL.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    mGL.glDrawElements(GL11.GL_TRIANGLE_STRIP, indexCount, GL11.GL_UNSIGNED_BYTE, 0);

    mGL.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    mGL.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    mGL.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    restoreTransform();
    mCountDrawMesh++;
  }
 public void draw() {
   GL11 gl = getGLManager().getGL();
   //   bind( );
   gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indices);
   gl.glDrawElements(GL10.GL_TRIANGLES, indices_length, GL10.GL_UNSIGNED_SHORT, 0);
   gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
 }
Exemple #4
0
  private void drawMesh(int x[], int y[], float u[], float v[], int nx, int ny) {
    /*
     * Given a 3x3 nine-patch image, the vertex order is defined as the
     * following graph:
     *
     * (0) (1) (2) (3)
     *  |  /|  /|  /|
     *  | / | / | / |
     * (4) (5) (6) (7)
     *  | \ | \ | \ |
     *  |  \|  \|  \|
     * (8) (9) (A) (B)
     *  |  /|  /|  /|
     *  | / | / | / |
     * (C) (D) (E) (F)
     *
     * And we draw the triangle strip in the following index order:
     *
     * index: 04152637B6A5948C9DAEBF
     */
    int pntCount = 0;
    float xy[] = mXyBuffer;
    float uv[] = mUvBuffer;
    for (int j = 0; j < ny; ++j) {
      for (int i = 0; i < nx; ++i) {
        int xIndex = (pntCount++) << 1;
        int yIndex = xIndex + 1;
        xy[xIndex] = x[i];
        xy[yIndex] = y[j];
        uv[xIndex] = u[i];
        uv[yIndex] = v[j];
      }
    }
    mUvPointer.asFloatBuffer().put(uv, 0, pntCount << 1).position(0);
    mXyPointer.asFloatBuffer().put(xy, 0, pntCount << 1).position(0);

    int idxCount = 1;
    byte index[] = mIndexBuffer;
    for (int i = 0, bound = nx * (ny - 1); true; ) {
      // normal direction
      --idxCount;
      for (int j = 0; j < nx; ++j, ++i) {
        index[idxCount++] = (byte) i;
        index[idxCount++] = (byte) (i + nx);
      }
      if (i >= bound) break;

      // reverse direction
      int sum = i + i + nx - 1;
      --idxCount;
      for (int j = 0; j < nx; ++j, ++i) {
        index[idxCount++] = (byte) (sum - i);
        index[idxCount++] = (byte) (sum - i + nx);
      }
      if (i >= bound) break;
    }
    mIndexPointer.put(index, 0, idxCount).position(0);

    mGL.glDrawElements(GL11.GL_TRIANGLE_STRIP, idxCount, GL11.GL_UNSIGNED_BYTE, mIndexPointer);
  }
  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);
  }
Exemple #6
0
 // Assumes beginDrawingStrips() has been called before this.
 public void drawStrip(GL10 gl, boolean useTexture, int startIndex, int indexCount) {
   int count = indexCount;
   if (startIndex + indexCount >= mIndexCount) {
     count = mIndexCount - startIndex;
   }
   if (!mUseHardwareBuffers) {
     gl.glDrawElements(
         GL10.GL_TRIANGLES, count, GL10.GL_UNSIGNED_SHORT, mIndexBuffer.position(startIndex));
   } else {
     GL11 gl11 = (GL11) gl;
     gl11.glDrawElements(GL11.GL_TRIANGLES, count, GL11.GL_UNSIGNED_SHORT, startIndex * CHAR_SIZE);
   }
 }
 public synchronized void draw(GL11 gl) {
   super.draw(gl);
   if (fontIndexCount > 0) {
     gl.glBindTexture(GL11.GL_TEXTURE_2D, mFont.id);
     gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, mTextureBuffer);
     gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mVertexBuffer);
     gl.glColorPointer(4, GL11.GL_FIXED, 0, mColorBuffer);
     mIndexBuffer.position(indStart);
     mColorBuffer.position(colorStart);
     mVertexBuffer.position(vertStart);
     mTextureBuffer.position(texStart);
     gl.glDrawElements(GL11.GL_TRIANGLES, fontIndexCount, GL11.GL_UNSIGNED_SHORT, mIndexBuffer);
   }
 }
    public void draw(GL10 gl) {
      checkGLError(gl);
      GL11 gl11 = (GL11) gl;

      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertexBufferObjectId);
      gl11.glVertexPointer(3, GL10.GL_FLOAT, VERTEX_SIZE, 0);

      gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
      gl11.glNormalPointer(
          GL10.GL_FLOAT, VERTEX_SIZE, VERTEX_NORMAL_BUFFER_INDEX_OFFSET * FLOAT_SIZE);

      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mElementBufferObjectId);
      gl11.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, 0);
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
      gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
      checkGLError(gl);
    }
  @Override
  protected void onDraw(Canvas canvas) {
    GL11 gl = (GL11) context.getGL();
    int w = getWidth();
    int h = getHeight();

    context.waitNative(canvas, this);

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, w, h);
    GLU.gluPerspective(gl, 45.0f, ((float) w) / h, 1f, 100f);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 5, 0, 0, 0, 0, 1, 0);
    gl.glTranslatef(0, 0, -10);
    gl.glRotatef(30.0f, 1, 0, 0);
    // gl.glRotatef(40.0f, 0, 1, 0);

    gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertices[frame_ix]);
    gl.glNormalPointer(GL10.GL_FIXED, 0, normals);
    gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, texCoords);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // gl.glColor4f(1,0,0,1);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
    // gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDrawElements(GL10.GL_TRIANGLES, verts, GL10.GL_UNSIGNED_SHORT, indices);

    frame_ix = (frame_ix + 1) % m.getFrameCount();
    context.waitGL();
  }
 @Override
 public void glDrawElements(int mode, int count, int type, int indices) {
   gl.glDrawElements(mode, count, type, indices);
 }
Exemple #11
-1
  public void draw(GL10 gl, boolean useTexture) {
    if (!mUseHardwareBuffers) {
      gl.glVertexPointer(3, mCoordinateType, 0, mVertexBuffer);

      if (useTexture) {
        gl.glTexCoordPointer(2, mCoordinateType, 0, mTexCoordBuffer);
      }

      gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
    } else {
      GL11 gl11 = (GL11) gl;
      // draw using hardware buffers
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
      gl11.glVertexPointer(3, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mTextureCoordBufferIndex);
      gl11.glTexCoordPointer(2, mCoordinateType, 0, 0);

      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferIndex);
      gl11.glDrawElements(GL11.GL_TRIANGLES, mIndexCount, GL11.GL_UNSIGNED_SHORT, 0);

      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);
    }
  }