• 用OpenGL ES 如何将2D图形更方便的渲染?


     其实很简单.自己就是个搬运工而已。。其实连搬运都谈不上了,就是 copy...   但这是我的心得体会。拿来和你分享。请你顺手点击AD 是对我的鼓励。

      翻译一下:   http://www.scottlu.com/2008/04/fast-2d-graphics-wopengl-es.html

      关键字: Pbuffer, glTexSubImage2D, glDrawTex, GL_TEXTURE_CROP_RECT_OES,

      原文如下,

      "Thankfully, OpenGL ES has created the concept of a "PBuffer". A PBuffer is both a surface for rendering onto, that can also be used as a pixel buffer for a texture. It is assumed that PBuffers dynamically update, so using a PBuffer as a texture is designed to be inexpensive. They key thing for your 2D game, is that uploading a new texture into your PBuffer is also fairly inexpensive, using glTexSubImage2D().

    Once your frame is composed in your PBuffer, you'll want to draw it onto your windowed surface. OpenGL ES v1.1 has a nice "extension api" called glDrawTex(). This is the fastest and easiest way of drawing a textured quad. Use this to draw your PBuffer contents to your window surface. Before you call glDrawTex(), be sure to set the clipping rectangle with glTexParameter / GL_TEXTURE_CROP_RECT_OES. Finally, your platform specific swap buffers api will copy your color buffer to the associated native window. This whole process will give you decent frame rates with minimal change to your existing game. To recap:

    1. Use glOrtho to set up a parallel projection, useful for your 2D game.
    2. Create a PBuffer surface and associate it with a texture name. Use powers of 2 dimensions.
    3. Use glTexSubImage to update only the parts of the PBuffer that are changing (worst case, the whole frame).
    4. Once the PBuffer is ready, draw it to your window surface by setting the cropping rect and calling glDrawTex.
    5. Swap buffers. Goto 3. "  

     在Opengl es 处理2D 的图像时, 文中提到了2种方式,

     1种是将所有的代码转换成 opengl es 的. 因为之前进行一些优化的处理,而现在需要重新修改,还有自定义格式的图形,(非标准的图像格式,可能经过压缩处理的) 都是如此, 这样的运行效率应该是最高的. 

     2种 就是每次刷新屏幕的时候, 刷新时都画在一个屏幕上, 然后更新 纹理贴图, 但是这个操作很慢. 因为机器要转换成GPU识别的优化的格式.

     然后提到了 Pbuffer 的概念,  They key thing for your 2D game, is that uploading a new texture into your PBuffer is also fairly inexpensive, using glTexSubImage2D().  

     在调用 glDrawTex 之前 要设置 GL_TEXTURE_CROP_RECT_OES 函数,  具体的步骤如下,

      1. 设置好投影.

      2. 创建 pBuffer 的surface, 然后绑定到纹理的名称.

      3. 用 glTexSubImage2D 更新指定的区域

      4  一旦 pBuffer 准备就绪, 就可以调用 drawTex 来完成了.

      5 Swap Buffers 刷新缓冲, 回到第3步。

    结合lipeng 同学前两天的问题, 似乎他就是用 glTexSubImage 来处理的, 不知道是否和这篇说的一致? 或者有一些遗漏的步骤没有处理好。看来这个原理上是行得通的。 待我这几天有时间来写一个Sample 测试一下。 

  • 相关阅读:
    利用Python编写简单的Web静态服务器(TCP协议)
    UDP-TCP介绍与区别
    Linux基本知识-命令
    Python中多线程与join()的应用
    Python实例---对一组含有四则运算,括号,空格的字符串进行计算
    分组查询注意事项
    oracle分页查询
    springMVC文件上传配置
    ssm网站页面乱码问题解决
    redis-server.exe闪退
  • 原文地址:https://www.cnblogs.com/cnsoft/p/1364458.html
Copyright © 2020-2023  润新知