什么是适用于 Windows/C++ 的好的 2D 图形绘制 API?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3621197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:10:06  来源:igfitidea点击:

What's a good 2D graphics drawing API for Windows/C++?

c++windowsapidirectxdrawing2d

提问by Jengerer

I've been working on a small little application, and I've been using DirectX/3D to draw textures to the screen (all 2-dimensional elements). The API, I find, is pretty easy to use and to incorporate using OOP principles, but I can't help but feel that using DirectX on something this small is insanely over-kill.

我一直在开发一个小的应用程序,我一直在使用 DirectX/3D 将纹理绘制到屏幕上(所有 2 维元素)。我发现 API 非常易于使用,并且可以使用 OOP 原则进行整合,但我不禁觉得在这么小的东西上使用 DirectX 是一种疯狂的过度杀伤。

I can't seem to find consensus on a good alternative, though. Any suggestions?

不过,我似乎无法就一个好的替代方案达成共识。有什么建议?

EDIT:Native alpha-blending and PNG file support is necessary.

编辑:本机 alpha 混合和 PNG 文件支持是必要的。

With much first-post love, Jengerer

Jengerer 有很多初恋

采纳答案by Ron Warholic

If you need alpha blending you have to use the graphics hardware; the only good way to do that is to use a 3D API similar to how you're doing it now (DirectX or OpenGL). Any alternative (GDI/+ or say, DirectDraw) will not use the full graphics hardware for accelerating blending and will have to perform it on the CPU, greatly reducing performance.

如果您需要 alpha 混合,则必须使用图形硬件;做到这一点的唯一好方法是使用类似于您现在的做法(DirectX 或 OpenGL)的 3D API。任何替代方案(GDI/+ 或 DirectDraw)都不会使用完整的图形硬件来加速混合,而必须在 CPU 上执行,从而大大降低性能。

As mentioned, Direct2D is an option also--it is functionally a layer on top of Direct3D that supports more 2D specific functionality as well as excellent text support.

如前所述,Direct2D 也是一个选项——它在功能上是 Direct3D 之上的一个层,支持更多 2D 特定功能以及出色的文本支持。

回答by Franci Penov

If you don't need XP support, use Direct2D.
Otherwise, use GDI+.

如果您不需要 XP 支持,请使用Direct2D
否则,请使用GDI+

回答by Ron Warholic

Windows includes one out of the box. (GDI32.DLL). It's possible to hook into the WM_PAINTmessage in the WindowProc call and use BeginPaint()to start drawing. A really good idea of what can be done and a basic tutorial is available on Zetcode.

Windows 包括一个开箱即用的。(GDI32.DLL)。可以WM_PAINT在 WindowProc 调用中挂钩消息并用于BeginPaint()开始绘图。Zetcode上提供了一个非常好的想法和基本教程。

回答by Jericho Kain

I have used Gosuin the past, and it has been alright to work with. It was designed to be used more with Ruby, but it is not bad for C++. We used it in a quick side scroller game, where we messed with z-order and the alpha channel. It might be worth checking out.

我过去使用过Gosu,使用起来没问题。它被设计为更多地与 Ruby 一起使用,但对于 C++ 来说也不错。我们在快速横向卷轴游戏中使用了它,在那里我们弄乱了 z-order 和 alpha 通道。可能值得一试。