Solution-to-graphics.h

Author

Setting up graphics library (graphics.h) in Visual Studio Code (c++)

Table Of Content

My Workspace Dir and code example

graphics example

General information

It like a tradition to use Turbo in our Indian CS sector. Its because the syllabus havenโ€™t been changed since long time.

The graphics. h header file provides access to a simple graphics library that makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on a graphical window. The second step is initialize the graphics drivers on the computer using initgraph method of graphics. h library.

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

Trust Me There are much better option

Allegro or SDL libraries may be for you. You could also try SFML. It has quite a following. Youโ€™ll have a large community behind you if you needed any help.


files

Setup

Know the difference between MINGW, Mingw-w64 && TDM learn more go, go, goโ€ฆ

UPDATE: switching from MinGW to TDM-GCC-32

Install TDM-GCC-32 from their official site link

|step1|step1| |โ€“|โ€“|

Get all the files needed graphics.h, winbgim.h and libbgi.a

location might be (โ€œC:/TDM-GCC-32/include/โ€)

location might be (โ€œC:/TDM-GCC-32/libโ€)

Open Vs Code Smart way:

   mkdir cppGraphics
   cd cppGraphics
   code .

if you are using template with task and c_cpp_properties json file then you directory should look like this:

cppGraphics
โ”œโ”€โ”€โ”€.vscode
โ””โ”€โ”€โ”€Home
    โ”œโ”€โ”€โ”€build
    โ””โ”€โ”€โ”€src

image

//create a file name it example.cpp inside src or any other name with .cpp extension

#include <graphics.h>

int main(){
    int gdrive = DETECT;
    int gmode;

    initgraph(&gdrive, &gmode, NULL);
    // you can also pass NULL for third parameter if you did above setup successfully
    // example: initgraph(&gd, &gm, NULL);

    arc(200, 200, 0, 360, 100);
    arc(150, 150, 0, 360, 20);
    arc(250, 150, 0, 360, 20);

    arc(200, 200, 0, 360, 5);
    arc(200, 250, 180, 360, 30);

    getch();
    closegraph();
}

Just Ctrl+Shift+B to run the build task you will get the executable file in build folder

image

graphics example2 graphics example3

Manual

Running the file using command in termainl:

    g++ -o example day3.cpp -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

    //after u'll get example.exe run using command: .\example

Now To set up graphics.h in vs code using MINGW:

alternative video instruction in hindi to setup graphics.h lib in vscode

[<img src=โ€https://i.imgur.com/P8xiypZ.pngโ€ alt=โ€How to setup graphic.h library in Visual Studio Code Computer Graphics in VS Code CGMA โ€œ width=โ€50%โ€ />](https://www.youtube.com/embed/ijrNSHwXDAc โ€œHow to setup graphic.h library in Visual Studio Code Computer Graphics in VS Code CGMAโ€ )

Alternative step wise instruction to setup MinGW along with graphics library (graphics.h)

Contributors โœจ

Thanks to these wonderful people:


Prakash4844

๐Ÿ’ฌ ๐Ÿ“–

sagargoswami2001

๐Ÿ’ฌ ๐Ÿ“– </tr> </table>