我们应该使用OpenGL的2D图形? [英] Should we use OpenGL for 2D graphics?

查看:164
本文介绍了我们应该使用OpenGL的2D图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们想制作像MS Paint这样的应用程序,我们应该使用OpenGL来渲染图形吗?
如果使用传统的GDI与OpenGL,我想谈谈性能。
如果存在一些更好的libs用于这个目的,请看我一个。

解决方案

GDI,X11, OpenGL ...渲染API,即你通常不用它们进行图像处理(你可以做到这一点,但它需要一些预防措施)。



在绘图像MS Paint这样的应用程序,如果它是基于像素的,您通常会使用习惯代码或特殊图像操作库来操作一些图片缓冲区,然后将完整缓冲区发送到渲染API。



如果您的数据模型由笔画和单个形状组成,即矢量图形,那么OpenGL将成为一个相当不错的后端。然而,可能需要考虑一些其他的矢量图形API,比如OpenVG(目前的实现位于OpenGL之上,但直接在GPU上运行的本地实现可能会出现)。

在您的使用场景中,您不会在当前计算机上遇到任何性能问题,因此请不要从该条件中选择您的API。在涉及纹理,alpha混合等方面,OpenGL肯定比GDI更快。然而,根据系统和GPU,纯粹的GDI可能会胜过OpenGL,因为绘制弧线或填充具有复杂缠绕规则的复杂自相交多边形等简单的东西。 p>

If we want to make an application like MS Paint, should we use OpenGL for render graphics? I want to mention about performance if using traditional GDI vs. OpenGL. And if there are exist some better libs for this purpose, please see me one.

解决方案

GDI, X11, OpenGL... are rendering APIs, i.e. you usually don't use them for image manipulation (you can do this, but it requires some precautions).

In a drawing application like MS Paint, if it's pixel based, you'll normally manipulate some picture buffer with customary code, or a special image manipulation library, then send the full buffer to the rendering API.

If your data model consists of strokes and individual shapes, i.e. vector graphics, then OpenGL makes a quite good backend. However it may be worth looking into some other API for vector graphics, like OpenVG (which in its current implementations sits on top of OpenGL, but native implementations operating directly on the GPU may come).

In your usage scenario you'll not run into any performance problems on current computers, so don't choose your API from that criteria. OpenGL is definitely faster than GDI when it comes to texturing, alpha blending, etc. However depending on system and GPU pure GDI may outperform OpenGL for so simple things like drawing an arc or filling a complex self intersecting polygon with complex winding rules.

这篇关于我们应该使用OpenGL的2D图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆