2011-12-09 37 views
0

我接觸FPS低是因爲,我嘗試使用OpenGL與Android,爲了讓2D遊戲:)用OpenGL在Android

這是我的工作方式:

我有一個類GlRender

public class GlRenderer implements Renderer 

在這個班,上onDrawFrame我做 GameRender()GameDisplay()

而就gameDisplay()我有:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
      // Reset the Modelview Matrix 
      gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Modelview Matrix 
      gl.glLoadIdentity();     //Reset The Modelview Matrix 


      // Point to our buffers 
      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
      gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 

      // Set the face rotation 
      gl.glFrontFace(GL10.GL_CW); 

      for(Sprites...) 
      { 
       sprite.draw(gl, att.getX(), att.getY()); 
      } 
      //Disable the client state before leaving 
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
      gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 

而在精靈的繪製方法,我有:

_vertices[0] = x; 
    _vertices[1] = y; 

    _vertices[3] = x; 
    _vertices[4] = y + height; 

    _vertices[6] = x + width; 
    _vertices[7] = y; 

    _vertices[9] = x + width; 
    _vertices[10] = y + height; 


    if(vertexBuffer != null) 
    { 
     vertexBuffer.clear(); 
    } 
    // fill the vertexBuffer with the vertices 
    vertexBuffer.put(_vertices); 
    // set the cursor position to the beginning of the buffer 
    vertexBuffer.position(0); 


    // bind the previously generated texture 
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); 

    // Point to our vertex buffer 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer.mByteBuffer); 
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer.mByteBuffer); 

    // Draw the vertices as triangle strip 
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, _vertices.length/3); 

我的問題是,我有一個低的幀速率,即使在30 FPS有時我會寬鬆一些框架只1精靈(但它與50相同)

我做錯了什麼?我如何改進FPS?

回答

1

一般而言,您不應該爲每個繪製的精靈改變頂點緩衝區。通過「一般」,除非你正在製作一個粒子系統,否則我幾乎意思是「從不」。即使如此,您仍然可以使用正確的流媒體技術,而不是一次寫四個。

對於每個精靈,您都有一個預先構建的四元組。爲了渲染它,你使用着色器uniform s將精靈從中立位置變換到你想要在屏幕上看到的實際位置。