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

4

8

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.

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

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

With much first-post love, Jengerer

Blatt answered 1/9, 2010 at 18:51 Comment(1)
Considering that most of the 4K demos that you see in the demoscene are using D3D, I wouldn't say it's insanely over-kill for a simple 2D app. Also D3DX supports .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm and .tga file formats.Cyclometer
L
5

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.

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.

Laura answered 1/9, 2010 at 18:59 Comment(3)
As far as DirectX/OpenGL goes, what would you recommend? I know it's a pretty hot topic in the world of programming, but in terms of performance and practicability, which would you say is the better choice?Blatt
You complained specifically that DirectX felt like over-kill; OpenGL has a much quicker time-to-market API to get you rolling. Since OpenGL was designed with C in mind however, you'll lose the nice encapsulation of the DirectX OO design and have to deal with the OpenGL state machine. Performance will be nearly identical between the two so go with the one that provides an API that is clear and understandable to you.Laura
By over-kill I meant that performance-wise, it seemed like it took much more resources than such a small application should ever make use of. I find that even the smallest DirectX applications carry a pretty heavy load. Thanks for the replies, it really helped out!Blatt
E
5

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

Ellis answered 1/9, 2010 at 18:55 Comment(0)
L
5

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.

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.

Laura answered 1/9, 2010 at 18:59 Comment(3)
As far as DirectX/OpenGL goes, what would you recommend? I know it's a pretty hot topic in the world of programming, but in terms of performance and practicability, which would you say is the better choice?Blatt
You complained specifically that DirectX felt like over-kill; OpenGL has a much quicker time-to-market API to get you rolling. Since OpenGL was designed with C in mind however, you'll lose the nice encapsulation of the DirectX OO design and have to deal with the OpenGL state machine. Performance will be nearly identical between the two so go with the one that provides an API that is clear and understandable to you.Laura
By over-kill I meant that performance-wise, it seemed like it took much more resources than such a small application should ever make use of. I find that even the smallest DirectX applications carry a pretty heavy load. Thanks for the replies, it really helped out!Blatt
Q
3

Windows includes one out of the box. (GDI32.DLL). It's possible to hook into the WM_PAINT message 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.

Quench answered 1/9, 2010 at 18:58 Comment(0)
W
1

I have used Gosu in 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.

Wehrmacht answered 1/9, 2010 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.