25

I have been searching to get the source code of the header file <graphics.h> and its associated library in order to integrate it with my C++ program.

At the same time, I am interested in those cross-platform libraries that works on more than one compiler. Just to be more explicit, I am talking about those libraries that are used for drawing shapes, lines, and curves in C++.

genpfault
  • 51,148
  • 11
  • 85
  • 139
CompilingCyborg
  • 4,760
  • 13
  • 44
  • 61
  • 5
    Possible duplicates: http://stackoverflow.com/questions/671395/a-simple-2d-cross-platform-graphics-library-for-c-or-c http://stackoverflow.com/questions/1924171/simple-c-graphics-library http://stackoverflow.com/questions/4496541/c-graphics-library-in-visual-studio-and-eclipse – user786653 Oct 22 '11 at 15:42
  • 2
    If you have old code referencing `graphics.h` or still want to use it for some reason, use [WinBGIm](http://winbgim.codecutter.org/), a modern port of the original. – legends2k Nov 02 '17 at 23:02
  • WinBGIm is modern in the same sense that GCC 3.3 is modern. You can do everything right, and it's still a coin toss whether or not a program using it will function on a PC that is modern in the "made in the last 5 years" sense. – user4581301 Mar 11 '21 at 20:53

5 Answers5

35

<graphics.h> is very old library. It's better to use something that is new

Here are some 2D libraries (platform independent) for C/C++

SDL

GTK+

Qt

Also there is a free very powerful 3D open source graphics library for C++

OGRE

feedc0de
  • 3,646
  • 8
  • 30
  • 55
ammar26
  • 1,584
  • 4
  • 21
  • 41
14

<graphics.h> is not a standard header. Most commonly it refers to the header for Borland's BGI API for DOS and is antiquated at best.

However it is nicely simple; there is a Win32 implementation of the BGI interface called WinBGIm. It is implemented using Win32 GDI calls - the lowest level Windows graphics interface. As it is provided as source code, it is perhaps a simple way of understanding how GDI works.

WinBGIm however is by no means cross-platform. If all you want are simple graphics primitives, most of the higher level GUI libraries such as wxWidgets and Qt support that too. There are simpler libraries suggested in the possible duplicate answers mentioned in the comments.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • WinBGIm is pretty old itself -- last updated in 2004?? -- and is not at all a standard API. –  Aug 29 '17 at 04:54
  • @duskwuff : I am not sure what point you are trying to make. It seems that it applies to the question rather than my answer. Being old is hardly an issue when the API it implements has not changed. I clearly stated that it is not a standard library. There is no standard library for graphics. All your points have already been made in existing answers, and the question itself is 6 years old (so at time of writing, WinBGIm was not nearly so old). – Clifford Aug 29 '17 at 05:49
  • 1
    @user4581301 I make the same point I made to user149341 4 years ago - the comment is misplaced against this answer. In fact it probably warrants an answer itself, since it addresses the cross-platform issue. If the question were not 10 years old that is. – Clifford Aug 17 '21 at 06:31
10

There is a modern port for this Turbo C graphics interface, it's called WinBGIM, which emulates BGI graphics under MinGW/GCC.

I haven't it tried but it looks promising. For example initgraph creates a window, and from this point you can draw into that window using the good old functions, at the end closegraph deletes the window. It also has some more advanced extensions (eg. mouse handling and double buffering).

When I first moved from DOS programming to Windows I didn't have internet, and I begged for something simple like this. But at the end I had to learn how to create windows and how to handle events and use device contexts from the offline help of the Windows SDK.

Calmarius
  • 18,570
  • 18
  • 110
  • 157
4

The Borland Graphics Interface, the library fronted by the graphics.h header, has been re-implemented atop SDL. This brings support for modern hardware and operating systems (multiple operating systems, in fact, since SDL is fairly portable).

It can be downloaded here prebuilt for a variety of common desktop targets.

Or if you wish to (or must) build it from source, here is a github mirror.

Note that it is a port of a very old software library and will run atop modern tools, so you should check with the instructor if you intend to use it for class assignments. It would be irritating to fail an assignment because you used idioms that require support from a modern compiler and find that they do not compile on a marking system from the 1980s.

You may find it better to get and develop with a virtual machine clone of the marking system to prevent nasty surprises.

user4581301
  • 33,082
  • 7
  • 33
  • 54
3

graphics.h appears to something once bundled with Borland and/or Turbo C++, in the 90's.

http://www.daniweb.com/software-development/cpp/threads/17709/88149#post88149

It's unlikely that you will find any support for that file with modern compiler. For other graphics libraries check the list of "related" questions (questions related to this one). E.g., "A Simple, 2d cross-platform graphics library for c or c++?".

tripleee
  • 175,061
  • 34
  • 275
  • 318
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331