24

如果您在 microsoft.com 上打开“图形和游戏 (Windows)”页面

最后一类被描述为

Legacy Graphics:过时且不应在新应用程序中使用的技术。

此类别包括(除其他外)以下 API:

  • GDI
  • GDI+
  • OpenGL

你怎么看?如果我今天想推出一个新软件,它必须支持 Windows XP(仍然是所有已安装系统的 50% 左右)。Direct2D 需要 Windows 7/Vista。还应该使用什么?

4

6 回答 6

15

我怀疑微软对“遗留”的定义与任何明智的开发人员应该做的事情几乎没有关系,而是基于对 Windows API 的一些大重写。

从 Windows Vista 开始,Microsoft 一直在重新设计他们的许多 API。我们现在将 MMDevAPI 作为 One True Sound API,WIC 是 One True Image File API,等等。据我所见/所闻,这些新 API 比旧 API 好得多,并且“遗留”系统都可以工作基于新的。在 Windows Vista 及更高版本中,DirectSound 完全基于 MMDevAPI,需要读取图像文件的组件通过 WIC 完成。

Windows 8 将有一个 ARM 版本,它似乎只支持当前 Windows API 的一个子集。在 ARM 上的 Windows 发布之前我们无法确定,但是,基于 Visual Studio 11 中为 ARM 平台包含的库(参考: http: //www.winehq.org/pipermail/wine-devel/2012- March/094559.html ),看起来 GDI+ 和 OpenGL 将不可用。GDI 可用于链接,但这并不一定意味着它是完整的。

这个来自 Vista 和更高版本的新 API 大致对应于 VS11 ARM 目标中的库。我猜该列表上的任何东西都在那里,因为它要么是最新和最伟大的方式来做它所做的事情,要么它在技术上太重要而不能丢弃(现在)。因此,“遗产”是任何不是做至少一件事的最新和最好的方式的东西。

我不确定 One True Graphics API 是什么。我们已经有了 Direct2D、Direct3D、DirectComposition(顺便说一句,直到 Windows 8 才可用)、DirectWrite 和 DXGI。DXGI 似乎是最接近的,但我对图形 API 的理解还不够深入。我怀疑 gdi32 在技术上很难摆脱。非传统应用程序如何在不使用涉及 HDC 的 WM_PAINT 的情况下找出窗口的一部分何时已显示并因此必须绘制,以及库如何在不替换其窗口过程的情况下代表应用程序执行此操作?我们如何在不使用需要 HDC 的 UpdateLayeredWindow 的情况下制作半透明窗口?user32对gdi32有多少依赖,真的能分开吗?

从技术角度来看,Windows 可以轻松摆脱 GDI+ 和 OpenGL,但我不相信摆脱 OpenGL 会奏效,即使是在不承诺任何向后兼容性的新平台上也是如此。这对开发人员来说似乎太有价值了。GDI+ 并不那么重要,但第三方很容易提供替代品。

我会说使用您列出的任何 API,最糟糕的情况是如果您想将应用程序移植到 Metro 或 ARM 上的 Windows,您必须重写您的 UI。如果您的需求很简单并且您将直接为 Windows API 编写代码,那么 GDI 是一个不错的选择。在很多情况下,我会推荐 GDI+ 而不是 OpenGL 作为绘图 API。GDI+ 速度慢、受限且仅在 Windows 上可用。GDI+ API 更简单,因为它是 2D 的,所以如果您需要做一些非常简单但具有抗锯齿功能的事情,那么它可能是值得的。

于 2012-04-05T01:01:34.010 回答
11

OpenGL 没有被弃用,微软的实现是. Microsoft 的实现停留在旧版本1.1。当前版本的标准是过去的版本 4。如果你想使用 OpenGL,它在 Windows 桌面上被NVidiaATIIntel显卡完全支持,但在Metro Windows Modern UI 应用程序中不支持,是一个行业标准,也适用于Mac和 Linux。如果您需要软件回退实现,Mesa 可以满足您的需求,它甚至可以在 DOS 上运行。(由于 Mesa 可以渲染到内存缓冲区中,它没有理由不能在现代 UI 应用程序中工作,但您可能不想这样做,因为它可能很慢。)值得注意的一点是 WGL,它的 API在 Windows 桌面上访问 OpenGL 功能依赖于 GDI(弃用),因此如果您想使您的应用程序面向未来,您可能想要使用类似FreeGLUTSDL的东西,这也让您获得平台独立性。

OpenGL ES是 OpenGL 的变体,适用于AndroidApple iOS。它也可以通过WebGL在 JavaScript 中访问,Internet Explorer 11 将支持几乎所有其他浏览器都已经支持)。ANGLE为 Windows 提供了 GLES 的硬件加速实现,它搭载 DirectX(版本 9 或 11),因此也应该在现代 UI 应用程序中工作。再一次,Mesa 涵盖了软件实施。

TL;DR:OpenGL 不仅没有被弃用,它是跨平台的、标准的,并且在行业中具有巨大的发展势头。GDI 和 GDI+,好吧,没那么多。

于 2013-07-12T23:56:50.853 回答
7

If you want to support Windows XP, then you're supporting a "legacy" operating system, and as such, using a "legacy" graphics framework is the logical choice.

Even if that weren't true, let's just say that I disagree with the advice given by the linked MSDN article. The "legacy" status here has more to do with which technology the Windows team thinks is cool this week. The status designation of "obsolete" just means that the group responsible is no longer accepting or fulfilling bug reports (except for critical security issues). Not too big of a deal—these technologies have been around long enough that they're fairly feature-complete and stable.

GDI isn't going anywhere, so if you need something rock-solid that is guaranteed to be supported anywhere and everywhere, that's what I would go with.

If you need a bit more 2D capabilities than GDI offers (e.g., alpha channel transparency), then you could consider using GDI+. It's nearly an order of magnitude slower than GDI, but that's not too big of an issue on modern machines with more power than you could ever want. This, too, is going to be supported for a very long time to come.

That said, if I were writing a new app today, I probably wouldn't bother with OpenGL. There's very little that it offers in benefits over Direct2D and DirectWrite, which are both what Microsoft is pushing as the replacements for GDI/GDI+. There might be some benefit to using OpenGL if you absolutely must target Windows XP because as far as I can tell, Direct2D/DirectWrite are only supported on Vista and later, but that's because (as I mentioned originally), Windows XP falls squarely into the "legacy" or "obsolete" camp itself. Alternatively, if you already know OpenGL well and don't have time or the desire to learn Direct2D/DirectWrite, then it might make sense to continue using it in a new application.

Don't let the verbiage of the MSDN article scare you. Choose whatever technology makes the most sense for your specific use case given all of the available information. By the time any of these technologies go away completely, you'll have to re-write the app completely for a dozen other reasons.

Edit: Hmm, it looks like DirectWrite has also been declared (by some people at least) "obsolete" as well, having been replaced by Direct2D. That's funny, it hasn't even been around long enough for me to bother learning it. I guess that only goes to support my earlier argument that "obsolete" simply designates that a particular technology is not what is currently considered to be in vogue by the Microsoft devs.

I'm personally waiting until all the bugs get worked out of this stuff (and we decide on a semi-permanent standard) before I make the switch for any of my applications. Everything I've seen written in DirectDraw or Direct2D has had serious rendering bugs and is a performance nightmare, even on reasonably competent machines. Sure, they only show up sometimes, under the right conditions, but that's too much for me. And I swear, the blurry text shows up all the time. Not being able to read what's on screen is a deal-killer for me and my users. GDI doesn't have this problem, and it's not going anywhere.

于 2012-04-05T02:37:29.513 回答
7

GDI、GDI+ 和 OpenGL 真的过时/弃用了吗?

这对于 OpenGL 是不正确的。OpenGL 4 允许您在 winxp 上使用几何着色器。DirectX 无法做到这一点(WINXP 不支持 DirectX 10 及更高版本)。它也是目前仅有的跨平台 3D API 之一。

从商业角度来看,MS 对推广 DirectX 很感兴趣,因为正是他们的技术将开发人员锁定在 Windows 平台上(他们也有兴趣让 DirectX 对开发人员更具吸引力,但那是另一回事了)。所以他们不热衷于推广 OpenGL 是有道理的。

还应该使用什么?

我建议尽可能停止使用特定于平台的技术。获取跨平台框架并将其用于您的应用程序。有用于 GUI 应用程序的 Qt、GTK、wxWidgets 和其他工具包,以及用于游戏的 SDL(和替代品)。这样,当平台开发人员决定做出您不喜欢的荒谬决定(例如在 WinXP 上不支持 DX10)时,您将能够以最低的开发成本转移到其他地方。Qt 也非常强大,目前我没有理由使用其他东西进行 GUI 开发。不过,未来情况可能会发生变化。

简而言之,在为某些平台进行开发时,您应该记住,平台开发人员的目标可能与您的意愿不符。发现您的资源已被锁定在单一平台上并不是很愉快的经历。您自己的目标应该是第一要务,如果操作系统开发人员试图让您使用某些您不喜欢的技术,那么您不应该支持该技术。

于 2012-04-05T04:30:35.057 回答
2

因为 OpenGL 是一种标准,它应该被视为与 C 或 C++ 一样被弃用,因此考虑整个 Windows API(如今由于 Wine 已经成为在每个 x86 机器 API 上运行一次的编译器)被认为是时间问题已弃用,取而代之的是 .NET 和 C#。

当我需要加速 3d 时,我将 GDI 用于简单的图形和 OpenGL。

另一个方面是,微软的 OpenGL 内置实现肯定会被视为已弃用,因为它只是 1.1 版或其他版本,但已经有很长一段时间了。

于 2012-04-13T10:06:44.737 回答
-2

是的,关于 OpenGL,它实际上在资源和显示方面的许多方面都优于 DirectX。它永远不会被微软推广,因为它不能拥有 OpenGL,更不用说大多数人不做研究,微软可以声称它已经过时了。事实是 opengl 是开源标准,并且发展速度比封闭的要快得多,因为它有超过 1 个开发人员付费工作。此外,微软与许多公司签订了仅使用微软软件发布的合同,这为微软带来了更多的业务,而较少使用更高级的 OpenGL 标准。如果你愿意的话,这是一个有趣的锁定,微软创建了这些合同,因此许多程序都是用 DirectX 编写的,以保持微软的业务,没有公司会拒绝它,因为微软拥有大约 80% 以上的家庭用户市场。

于 2012-07-13T01:13:54.427 回答