用OpenGL ES 如何将2D图形更方便的渲染?
2012-09-02 12:52
337 查看
翻译一下: 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 测试一下。
关键字: 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 测试一下。
相关文章推荐
- 用OpenGL ES 如何将2D图形更方便的渲染?
- 如何使drawrect:画出的图形响应事件 Quartz 2d 事件 touch
- 如何使drawrect:画出的图形响应事件 Quartz 2d 事件 touch
- OpenGL es 2.0 实战 - 渲染图形变形
- molehill中2D简单图形的渲染,实例程序囫囵吞枣试的快速阅读
- android studio | openGL es 3.0增强现实(AR)开发 (4) 绘制简单的2D图形、显示、旋转
- GPU渲染时代——2D图形图像中的应用(一)
- OpenGL ES开发绘制2D图形
- OpenGL ES教程系列_LessonY_使用2D纹理渲染文字
- 如何使drawrect:画出的图形响应事件 Quartz 2d 事件 touch
- 走进WPF系列学习之二 如何用WPF绘制与配置2D图形界面
- Direct2D渲染图形
- 罗大柚OpenGL ES教程系列_LessonY_使用2D纹理渲染文字
- /LGC图形渲染/Typical UI development with OpenGL ES
- /LGC图形渲染/如何判断是否启用了硬件加速
- /LGC图形渲染/OpenGL ES 概述
- CAD编辑器中如何渲染图形?
- GPU渲染时代——2D图形图像中的应用(二)
- /LGC图形渲染/OpenGL ES 系列教程
- iOS Quartz 2D 绘制图形(线段\三角形\矩形\圆\圆弧等)