OpenGL ES 1禁用的东西和技巧.x编程(Android)



这个问题是关于OpenGL ES 1的。

我遵循了这个教程,并在三星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吗?
  • 是否值得直接使用OpenGL ES 2.0?

到目前为止,我没有找到任何关于OpenGL ES 1的好的和复杂的书。我向Stackoverflow的尊贵用户提出这个问题。

定义延迟?查看帧率可能有助于更好地了解性能。

但是老实说,只要square.draw(gl)做了它所暗示的,那么这就是一个非常简单的程序。这段代码对性能没有太大影响。

我得到的感觉,虽然这是一个更大的项目更投机的问题。需要考虑的是你想要达到什么样的图形效果。将OpenGL ES 1。X对你来说足够强大吗?如果你需要编写自定义着色器代码,你必须使用ES 2.0。记住,2.0要求你把所有东西都写成shader。它去掉了1.0的许多特性,并将这些特性交给开发人员来实现和定制。因此,开发将更加复杂和耗时。

作为一个警告,不要直接进入NDK作为起点。所有这些OpenGL调用都是原生的。比起使用JNI在C/c++中编写Android应用程序,在Java中编写Android应用程序要容易得多。

作为最后一句话,早期优化是万恶之源。一旦您选择了技术,实现了解决方案,并测量了其性能,您就可以开始考虑优化代码了!

最新更新