2011-11-06 51 views
1

這個問題是關於OpenGL ES的1.x的程序爲Android的技巧。故宮的東西和OpenGL ES 1.x的編程(安卓)

我跟着this tutorials和三星Galaxy Ace上的測試代碼,它滯後了一下。 該教程的一些代碼:

public void onDrawFrame(GL10 gl) { 
    // Clears the screen and depth buffer. 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
    // Replace the current matrix with the identity matrix 
    gl.glLoadIdentity(); 
    // Translates 10 units into the screen. 
    gl.glTranslatef(0, 0, -10); 

    // SQUARE A 
    // Save the current matrix. 
    gl.glPushMatrix(); 
    // Rotate square A counter-clockwise. 
    gl.glRotatef(angle, 0, 0, 1); 
    // Draw square A. 
    square.draw(gl); 
    // Restore the last matrix. 
    gl.glPopMatrix(); 

    // SQUARE B 
    // Save the current matrix 
    gl.glPushMatrix(); 
    // Rotate square B before moving it, making it rotate around A. 
    gl.glRotatef(-angle, 0, 0, 1); 
    // Move square B. 
    gl.glTranslatef(2, 0, 0); 
    // Scale it to 50% of square A 
    gl.glScalef(.5f, .5f, .5f); 
    // Draw square B. 
    square.draw(gl);    

    // SQUARE C 
    // Save the current matrix 
    gl.glPushMatrix(); 
    // Make the rotation around B 
    gl.glRotatef(-angle, 0, 0, 1); 
    gl.glTranslatef(2, 0, 0); 
    // Scale it to 50% of square B 
    gl.glScalef(.5f, .5f, .5f); 
    // Rotate around it's own center. 
    gl.glRotatef(angle*10, 0, 0, 1); 
    // Draw square C. 
    square.draw(gl); 

    // Restore to the matrix as it was before C. 
    gl.glPopMatrix(); 
    // Restore to the matrix as it was before B. 
    gl.glPopMatrix(); 

    // Increse the angle. 
    angle++; 
} 
  • 什麼這裏有一週的部分?
  • 應該如何優化Android的OpenGL ES程序?
  • 我應該在大型圖形項目中使用NDK嗎?
  • 是否值得Goind直接指向OpenGL ES 2.0?

至於我沒有找到任何有關Android的OpenGL ES 1.x編程的優秀和複雜的書,我將這個問題解答給了尊敬的Stackoverflow用戶。 希望得到任何幫助。

+0

注意,Android上的OpenGL ES在模擬器和調試模式比當你只是一個設備上運行它正常多了不少落後了 –

回答

0

定義滯後?查看幀速率以獲得更好的性能感覺可能會有所幫助。

但TBH,只要square.draw(gl)是做什麼暗示,那麼這是一個非常簡單的程序。這段代碼沒有什麼性能。

我得到的感覺,雖然這是更多更大的項目投機問題。有些事情要考慮的是你會試圖達到什麼樣的圖形效果。 OpenGL ES 1.x對你來說足夠強大嗎?如果您需要編寫自定義着色器代碼,則必須使用ES 2.0。請記住,2.0需要你將所有東西都寫成着色器。它挖掘了許多1.0功能,並將這些功能提供給開發人員實施和定製。所以開發將變得更加複雜和耗時。

作爲warining,不直接潛入NDK爲出發點。所有這些OpenGL調用都是原生的。在Java領域編寫Android應用程序比使用JNI的C/C++要容易得多(很多)。

作爲最後一個字,早期的優化是一切罪惡的根源。一旦你選擇了你的技術,實施了一個解決方案並測量了它的性能,你就可以擔心優化代碼!