示例#1
0
  public void bind() {
    GL11 gl = (GL11) glGraphics.getGL();

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, vboHandle);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, vertexSize, 0);

    if (hasColor) {
      gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
      gl.glColorPointer(4, GL10.GL_FLOAT, vertexSize, 3 * 4);
    }

    if (hasTexCoords) {
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
      gl.glTexCoordPointer(2, GL10.GL_FLOAT, vertexSize, (hasColor ? 7 : 3) * 4);
    }

    if (hasNormals) {
      gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
      int offset = 3;
      if (hasColor) offset += 4;
      if (hasTexCoords) offset += 2;
      gl.glNormalPointer(GL10.GL_FLOAT, vertexSize, offset * 4);
    }
  }
    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();
  }
示例#4
0
 @Override
 public void glNormalPointer(int type, int stride, int pointer) {
   gl.glNormalPointer(type, stride, pointer);
 }