7

I'm new to graphics programming and I'm wondering why I would ever prefer GDI over the hardware accelerated graphics of DirectX/OpenGL?

Are there still good reasons to use GDI?

Bart
  • 19,692
  • 7
  • 68
  • 77
xcrypt
  • 3,276
  • 5
  • 39
  • 63

2 Answers2

10

It ultimately comes down to what you need. If you just need non-real time 2D graphics, GDI will do exactly what you need.

On the other hand, DirectX and OpenGL take much more work to use and manage (and typically use more system resources), although they allow faster drawing, and 3D.

Remember, keep it simple, you don't need a full 3D system to draw a couple of circles!

slugonamission
  • 9,562
  • 1
  • 34
  • 41
  • 2
    Yeah this. Basically GDI is just simple. If you aren't doing anything extensive whatsoever and you don't understand how OpenGL or DirectX work then it probably isn't in your best interest to learn about them. And GDI is platform specific whereas OpenGL is cross-platform. – Andrew Rasmussen Nov 28 '11 at 22:35
  • So with GDI the size of my exe file will be smaller, but will have slower drawing? So basically if I want fast drawing, I should use DirectX/OpenGL, else GDI? So for paint programs, 2D/3D games, etc, it would be more efficient to use DX/GL, and for programs that don't need to refresh the window that often, GDI is a better choice? – xcrypt Nov 28 '11 at 22:35
  • 1
    Not exactly. Your program size shouldn't change much as the OpenGL/DirectX libraries are dynamically linked (although of course, you have more code to init them). GDI *will* be slower than D3D/OpenGL though, as it's indirect rendering. Both D3D and OGL talk straight to the graphics card, GDI has to go through Windows and (I think) is all done in software. – slugonamission Nov 28 '11 at 22:37
  • Actually, I think some more recent versions of Windows try to hardware accelerate GDI. Still though, if you need very fast 2D or 3D graphics, you're going to need D3D/OGL. – slugonamission Nov 28 '11 at 22:38
  • Well, I know how to use DX, but I don't really know GDI that well x) wouldn't it be better if I just always used it then? – xcrypt Nov 28 '11 at 22:40
  • It depends. As I said, if you need to make it fast, yeah, you're going to need DirectX. If you can take the performance hit and you're not doing anything too complicated, GDI will probably do it. Your best bet may be to try it with both to figure out which fits for you. – slugonamission Nov 28 '11 at 22:41
0

If you need to render text; GDI is pretty much infinately a better choice. Unless you are ready to learn how to parse font files and draw fonts. SFML does some nice text drawing but uses 32 bits for each character.

user13947194
  • 337
  • 5
  • 7