0% found this document useful (0 votes)
53 views

C Graphics

This program initializes graphics mode in C by including the graphics header file, declaring variables for the graphics driver and mode, calling initgraph to start graphics with the maximum screen resolution, pausing with getch until a key is pressed, and closing the graphics mode with closegraph. It demonstrates the basic steps to initialize simple graphics output in C by detecting and starting the graphics mode, waiting for input, and ending the graphics mode.

Uploaded by

SUNIL
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

C Graphics

This program initializes graphics mode in C by including the graphics header file, declaring variables for the graphics driver and mode, calling initgraph to start graphics with the maximum screen resolution, pausing with getch until a key is pressed, and closing the graphics mode with closegraph. It demonstrates the basic steps to initialize simple graphics output in C by detecting and starting the graphics mode, waiting for input, and ending the graphics mode.

Uploaded by

SUNIL
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

C graphics

Sample graphics code


#include<graphics.h> #include<conio.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); getch(); closegraph(); return 0; }

this program initializes graphics mode and then closes it after a key is pressed. To begin with we have declared two variables of int type gd and gm for graphics driver and graphics mode respectively, you can choose any other variable name as you wish. DETECT is a macro defined in "graphics.h" header file, then we have passed three arguments to initgraph function first is the address of gd, second is the address of gm and third is the path where your BGI files are present ( you have to adjust this accordingly where you turbo compiler is installed). Initgraph function automatically decides an appropriate graphics driver and mode such that maximum screen resolution is set, getch helps us to wait until a key is pressed, closegraph function closes the graphics mode and finally return statement returns a value 0 to main indicating successful execution of your program. After you have understood initgraph function then you can use functions to draw shapes such as circle, line , rectangle etc, then you can learn how to change colors and fonts using suitable functions, then you can go for functions such as getimage, putimage etc for doing animation.

You might also like