Difference between revisions of "C++ Drawing to the screen"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=Using Graphics.h= There are many libraries for drawing graphics to the screen, these examples will show the standard 'Graphics.h' approach. You can the required files from: [...")
(No difference)

Revision as of 12:47, 13 June 2019

Using Graphics.h

There are many libraries for drawing graphics to the screen, these examples will show the standard 'Graphics.h' approach. You can the required files from: This Link . You will need to get 'graphics.h', 'winbgim.h', and the 'libbgi.a' files.

Drawing a Line

// C++ Implementation for drawing line

  1. include <graphics.h>
  2. include <winbgim.h>

// driver code int main() {

   // gm is Graphics mode which is a computer display 
   // mode that generates image using pixels. 
   // DETECT is a macro defined in "graphics.h" header file 
   int gd = DETECT, gm; 
 
   // initgraph initializes the graphics system 
   // by loading a graphics driver from disk 
   initgraph(&gd, &gm, ""); 
 
   // line for x1, y1, x2, y2 
   line(150, 150, 450, 150); 
  
   getch(); 
 
   // closegraph function closes the graphics 
   // mode and deallocates all memory allocated 
   // by graphics system . 
   closegraph(); 

}