Android開發之OpenGL ES 3D空間與glDrawArrays

來源:互聯網
上載者:User

  1.四稜錐: 由4個三角形構成。

  四方體: 由6個三角形構成。

  痛點:在構建3D空間的頂點座標時,要讓對象繞自身的軸旋轉,必須讓對象的中心座標總是(0.0f,0.0f,0.0f),

  並且三角形都是按逆時針次序繪製的。

  2.3D空間的繪製:

  GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count);

  參數說明:

  mode,繪製方式,OpenGL2.0以後提供以下參數:GL_POINTS、GL_LINES、GL_LINE_LOOP、GL_LINE_STRIP、GL_TRIANGLES、GL_TRIANGLE_STRIP、GL_TRIANGLE_FAN。

  first,從數組緩衝中的哪一位開始繪製,一般為0。

  count,數組中頂點的數量。

  3.繪製頂點數組:

  //繪製三角錐

  for(int i=0; i<4; i++)

  {

  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*3, 3);

  }

  //繪製四方體

  for(int i=0; i<6; i++)

  {

  gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*4, 4);

  }

  [附]構建頂點數組:

  [java]

  int one = 0x10000;

  // 四稜錐頂點數組:

  private IntBuffer triggerBuffer = IntBuffer.wrap(new int[]{

  0,one,0,

  -one,-one,0,

  one,-one,one,

  0,one,0,

  one,-one,one,

  one,-one,-one,

  0,one,0,

  one,-one,-one,

  -one,-one,-one,

  0,one,0,

  -one,-one,-one,

  -one,-one,one

  });

  // 四方體頂點數組:

  private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{

  one,one,-one,

  -one,one,-one,

  one,one,one,

  -one,one,one,

  one,-one,one,

  -one,-one,one,

  one,-one,-one,

  -one,-one,-one,

  one,one,one,

  -one,one,one,

  one,-one,one,

  -one,-one,one,

  one,-one,-one,

  -one,-one,-one,

  one,one,-one,

  -one,one,-one,

  -one,one,one,

  -one,one,-one,

  -one,-one,one,

  -one,-one,-one,

  one, one, -one,

  one, one, one,

  one, -one, -one,

  one, -one, one,

  });

  int one = 0x10000;

  // 四稜錐頂點數組:

  private IntBuffer triggerBuffer = IntBuffer.wrap(new int[]{

  0,one,0,

  -one,-one,0,

  one,-one,one,

  0,one,0,

  one,-one,one,

  one,-one,-one,

  0,one,0,

  one,-one,-one,

  -one,-one,-one,

  0,one,0,

  -one,-one,-one,

  -one,-one,one

  });

  // 四方體頂點數組:

  private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{

  one,one,-one,

  -one,one,-one,

  one,one,one,

  -one,one,one,

  one,-one,one,

  -one,-one,one,

  one,-one,-one,

  -one,-one,-one,

  one,one,one,

  -one,one,one,

  one,-one,one,

  -one,-one,one,

  one,-one,-one,

  -one,-one,-one,

  one,one,-one,

  -one,one,-one,

  -one,one,one,

  -one,one,-one,

  -one,-one,one,

  -one,-one,-one,

  one, one, -one,

  one, one, one,

  one, -one, -one,

  one, -one, one,

  });

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.