1

I'm using graphics.h in order to start with a bit of graphic in C++, but when I run the code the program crash. I'm using CodeBlocks as a compiler and Windows 8.1 as an operating system. What should I do in order to make it works? Here is the code:

#include <graphics.h>

int main()
{
    int gd = DETECT;
    int gm;
    initgraph(&gd, &gm, "C:\\TC\\BGI");

    arc(200, 200, 0, 130, 50);

    getch();
    closegraph();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1
    If you are using the old Borland grahpics.h I don't believe it will work with windows 8.1. It was written for win95/98 and a real dos prompt. – NathanOliver Feb 28 '19 at 15:27
  • 1
    You can't make it work. Forget about graphics.h –  Feb 28 '19 at 15:27
  • 2
    Oh my, `graphics.h`. It's been 20 years since I have seen it last time. Are you an archaeologist? – SergeyA Feb 28 '19 at 15:29
  • I believe you need to downgrade to a mingw release from 10+ years ago. The latest release of winbgim was from 2005. http://winbgim.codecutter.org/ – drescherjm Feb 28 '19 at 15:30
  • Please see my answer [here](https://stackoverflow.com/questions/55773892/how-to-solve-codeblocks-unable-to-run-a-graphics-c-program-properly/57507125#57507125), it may help you solve your problem. – kiner_shah Aug 15 '19 at 08:55

2 Answers2

1

"What should I do to make it works?"

1) Forget about graphics.h it is obsolete.

2) Get yourself a modern compiler (for example; Clang 7.1, GCC 8.3 or Visual Studio 2017).

3) Pick a modern graphics library. SFML and SDL are popular options.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
0

An alternative to BGI's graphics.h is TX Library. See here: https://sourceforge.net/projects/txlib. The docs are here: http://storage.ded32.net.ru/Lib/TX/TXUpdate/Doc/HTML.ru). The docs are currently in Russian.

A simple example:

#include "TXLib.h"

int main()
{
    txCreateWindow (800, 600);

    txLine   (320, 290, 320, 220);
    txLine   (320, 290, 280, 350);
    txLine   (320, 290, 360, 350);
    txLine   (320, 230, 270, 275);
    txLine   (320, 230, 400, 220);
    txCircle (320, 190, 30);

    txSelectFont ("Times New Roman", 60);
    txTextOut (240, 400, "Hello, world!");

    txArc (100, 100, 300, 200, 45, 270);

    return 0;
}
ded32
  • 316
  • 1
  • 11