Installing Borland Turbo C DOS Graphics Emulation (graphics.h) under Code::Blocks

(for using graphics.h under DEV-C++ see http://www.uniqueness-template.com/devcpp/)

 Michael Main has implemented a BGI empulation graphics library for Windows applications (based on the Borland Turbo C++ DOS graphics library) to be used under MinGW (and therefore Dev-C++ and Code::Blocks) .

 

Download:  The required files are:

graphics.h  (download to C:\CodeBlocks\MinGW\include)
libbgi.a (download to C:\CodeBlocks\MinGW\lib)

 

Link to graphics library: After opening a  Code::Blocks console project which uses graphics.h you need to set up the libraries for the linker.

In  Project > Build Options > Linker Settings > Other Linker options add the following
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32

 

Operation: You can now use <graphics.h>, e.g. try this simple program (from  http://www.uniqueness-template.com/devcpp/)

  #include <graphics.h>
 
  int main() 
  { 
      initwindow(400,300); //open a 400x300 graphics window
      moveto(0,0);         
      lineto(50,50);       
      while(!kbhit());     //wait for user to press a key
      closegraph();        //close graphics window
      return 0; 
  }

i.e. create a new Code::Blocks console application project, paste the above code into the main.cpp file, set up the link to the graphics library (described above), compile and run.