Skip to content

ashalupreti/c-cpp-graphics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Author

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

Table Of Content

Example

graphics example

General information

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

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

If you don't have MinGW installed get it from official and follow the steps.

  • Copy graphics.h and winbgim.h files to MinGW/include folder.

location might be ("C:\MinGW\include")

  • Copy libbgi.a to file to MinGW/lib folder.

location might be ("C:\MinGW\lib")

Open Vs Code Smart way:

  • Select a folder and open Terminal
   mkdir C-Cpp-graphics
   cd C-Cpp-graphics
   code .

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

  • All you code should o inside src and the task.json will build the .exe in build folder
C-Cpp-graphics
├───.vscode
└───Home
    ├───build
    └───src
  • Get the template from the repo .vscode config which will contain task.json, c_cpp_properties.json

image

#include <graphics.h>
    int main()
    {
        int gd = DETECT, gm;
        char data[] = "C:\\MinGW\\lib\\libbgi.a";

        initgraph(&gd, &gm, data);


        circle(200, 200, 100);
        getch();
        closegraph();
        return 0;
    }

Running the file using command in termainl:

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

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

image

OR

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

graphics example2) graphics example3

Easy run template for graphics.h repo If your dont want to write that command again and again you can create task.json

Compiler:

  • Setup MingW 32 compiler path in environment variables.
  • Insert graphics.h and winbgim.h header file from the graphics file winbgim file libbgi file in mingw's include folder and libbgi.a file into lib folder of mingw folder that we've installed already

Quick setup

git clone https://github.com/ashalupreti/c-cpp-graphics
  • Just Ctrl+Shift+B to run the build task you will get the executable file in build folder

!mportant

  • Folder src contains source code

  • Folder build where compiler generate .exe

  • .vscode contains c_cpp_properties.json and task require modification according to your environment and types compiler

Releases

No releases published

Packages

No packages published

Languages