【问题标题】:Forbidden things and tricks of OpenGL ES 1.x programming(Android)OpenGL ES 1.x 编程的禁忌和技巧(Android)
【发布时间】:2012-02-28 06:31:32
【问题描述】:

这个问题是关于 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?
  • 是否值得直接使用 OpenGL ES 2.0?

就我没有找到任何关于适用于 Android 的 OpenGL ES 1.x 编程的优秀而复杂的书籍而言,我向 Stackoverflow 的尊贵用户提出了这个问题。 将不胜感激。

【问题讨论】:

  • 请注意,android 上的 openGL-es 在模拟器和调试模式下比在设备上正常运行时滞后得多

标签: android graphics opengl-es


【解决方案1】:

定义滞后?查看帧速率以更好地了解性能可能会有所帮助。

但是TBH,只要square.draw(gl) 正在做它所暗示的,那么这是一个非常简单的程序。这段代码没有什么性能问题。

我的感觉是,对于一个更大的项目来说,这更像是一个推测性的问题。需要考虑的一些事情是您将尝试实现什么样的图形效果。 OpenGL ES 1.x 对你来说足够强大吗?如果需要编写自定义着色器代码,则必须使用 ES 2.0。但请记住,2.0 要求您将所有内容都编写为着色器。它删除了许多 1.0 特性,并将这些特性提供给开发人员来实现和定制。所以开发会更复杂也更耗时。

作为警告,不要直接将 NDK 作为起点。所有这些 OpenGL 调用已经是原生的。在 Java 领域编写 Android 应用程序将比使用 JNI 在 C/C++ 中容易得多(多得多)。

总而言之,早期优化是万恶之源。一旦您选择了您的技术、实施了一个解决方案并衡量了它的性能,您就可以开始着手优化代码了!

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    相关资源
    最近更新 更多