简体   繁体   中英

Drawing an arc in C++ Graphics.h

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();
}

"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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM