Basic Graphic Programming in C++

C++Server Side ProgrammingProgramming

C++ programming language is a versatile programming language. Using C++ you can create low end graphics too i.e. creating basic shapes and words with stylish fonts and adding colors to them can be done using c++.

Graphic programming can be done in c++ using your terminal or command prompt or you can download DevC++ compiler to create graphic programs.

For terminal you need to add the graphics.h libraray to you GCC compiler. For this you will have type in the following commands.

>sudo apt-get install build-essential
>sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0
\ guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev
\ libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev
\ libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev
\ libslang2-dev libasound2 libasound2-dev
>sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib

On sequentially typing all the above commands you can successfully install the graphics.h library in your GCC compiler of terminal.

for or the other method you need to install the DevC++ compiler.

graphics.h library − The graphic.h library is used to add graphics to your C++ program. For graphic programming, it is a must include library as it contains all required methods.

Syntax for including graphics in c++ program &ninus;




Program to show implementation of graphic programming in c++ −

using namespace std;
int main() {
   int gd = DETECT, gm;
   initgraph(−gd, −gm, "C:\\TC\\BGI");
   return 0;


Other Common functions of of C++ graphic programming are −

  • arc() − creates arc of a given angle and given radius.

  • bar() − creates a bar with given coordinates.

  • circle() − creates a circle of given radius.

  • closegraph() − it closed the graphics mode and deallocated memory chunks.

  • ellipse() − creates an ellipse with given major and minor axis.

  • floodfill() − flood fill is used to fill a specific color to a specific point whose coordinates are given.

  • line() − creates a line of given starting and ending points.

  • rectangle() − creates a rectangle with given coordinates.

Published on 22-Nov-2019 11:34:51