Git Product home page Git Product logo

solution-to-graphics.h's Introduction

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
  • after that default step that's all

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

  • Copy graphics.h and winbgim.h files to TDM-GCC-32/include folder.

location might be ("C:/TDM-GCC-32/include/")

  • Copy libbgi.a to file to TDM-GCC-32/lib folder.

location might be ("C:/TDM-GCC-32/lib")

Open Vs Code Smart way:

  • Select a folder and open Terminal
   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:

  • All your code should be inside src and the task.json will build the .exe in build folder
cppGraphics
β”œβ”€β”€β”€.vscode
└───Home
    β”œβ”€β”€β”€build
    └───src
  • .vscode folder in that workspace which will contain task.json, c_cpp_properties.json

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

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

πŸ’¬ πŸ“–

solution-to-graphics.h's People

Contributors

prakash4844 avatar sagargoswami2001 avatar ullaskunder3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

solution-to-graphics.h's Issues

Graphics.h doesn't work with gcc (Rev1, Built by MSYS2 project) 11.3.0

Hey first of all I would like to express gratitude to this repo and its author.

I tried to set up graphic.h and in Visual Studio code, but code doesn't compile with the following error.

> Executing task: C/C++: g++.exe build active file <

Starting build...
C:\msys64\mingw64\bin\g++.exe -g "D:\Users\Zaphkil!\Documents\VS Code\C++ Graphics\Home\src\example.cpp" -o "D:\Users\Zaphkil!\Documents\VS Code\C++ Graphics\Home\build\example.exe" -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../lib/libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../lib\libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../..\libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:\msys64\mingw64\x86_64-w64-mingw32\bin\../../../mingw64/lib/libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:\msys64\mingw64\x86_64-w64-mingw32\bin\../../../mingw64/lib\libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../lib/libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:\msys64\mingw64\x86_64-w64-mingw32\bin\../../../mingw64/lib/libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lbgi: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../lib/libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../libbgi.a when searching for -lbgi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:\msys64\mingw64\x86_64-w64-mingw32\bin\../../../mingw64/lib/libbgi.a when searching for -lbgi
collect2.exe: error: ld returned 1 exit status

Build finished with error(s).

Terminal will be reused by tasks, press any key to close it.

I am using gcc which was downloaded through msys2.

graphics.h works as intended with gcc 6.3.0 that is downloaded through mingw64 installer.

How can i fix this issue?

Segmentation Fault

I'm trying to get this library working with vscode following your guide but I get a segmentation fault!

I can successfully build the project with ctl+shift+b and this produces a lovely executable. If I try to run this nothing happens, if i open it within the console no error messages are displayed. The segmentation fault appears on initgraph. This is probably something to do with the library .a file...

Thank you!

fatal error

PS C:\Users\Subhajit\Desktop\project\cpp\collage lab\testFolder> g++ -o testfile example.cpp -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
example.cpp:2:14: fatal error: graphics.h: No such file or directory
2 | #include <graphics.h>
| ^~~~~~
compilation terminated.

Query

Hi,
I'm new to GitHub so idk how to ask a query, that's why I'm writing it here.
First of all thanks for this amazing solution. I managed to add the compile options in tasks.json & found a way to run it through code-runner extension.

My query : Do you know how can we combine the 'WIndows BGI' popup window (that comes at the time of running the program) with the terminal?
Because I've been working on user input programs and I have to write the user input separately in the integrated terminal of VS code.
Like in TurboC, the output of printf commands as well as the graphics commands(like line, rectangle, arc) comes in the same window. But in VS code, I've to use the outtextxy command so that the input strings show in the Windows BGI.

Do let me know if you know how to fix this.

Incomplete file

graphics.h file doesn't contain complete function definitions for some functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.