首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenGL ES 1.x编程(Android)的禁忌和技巧

OpenGL ES 1.x编程(Android)的禁忌和技巧
EN

Stack Overflow用户
提问于 2011-11-06 18:20:45
回答 1查看 508关注 0票数 1

这个问题是关于Android.的OpenGL es1.x编程

我遵循本教程并测试了三星Galaxy上的代码,它有点滞后。本教程的一些代码:

代码语言:javascript
复制
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++;
}
  • 这一周的时间是什么?
  • 我们应该做些什么来优化安卓的OpenGL ES程序?
  • 我应该在大型图形项目中使用NDK吗?
  • 直接去OpenGL ES 2.0值得吗?

至于我没有找到任何好的和复杂的书,关于OpenGL ES 1.x编程的安卓,我提出这个问题的尊敬的用户的斯塔克溢出。会很感激你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2012-02-27 22:31:32

定义滞后?查看框架以获得更好的性能感觉可能会有所帮助。

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

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

作为一个警告,不要直接跳入NDK作为起点。所有这些OpenGL调用都是本机的。用Java语言编写Android应用程序要比用JNI编写C/C++要容易得多。

归根结底,早期优化是万恶之源。一旦您选择了您的技术,实现了一个解决方案,并度量了它的性能,那么您就可以担心优化代码了!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8029269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档