Computer Graphics
Computer Graphics
Programming in
LAB-1 C
Date:31/1/2024
Contents
X+
Y+
640 x 480
❑ First of all, we must include the ”graphics.h” header file in our source program
❑In codeblocks open "Settings >> Compiler >>linker settings" click "Add" button in link
libraries part and browse and select "libbgi.a" file
❑In right part (i.e. other linker options) paste commands "-lbgi -lgdi32 -lcomdlg32 -luuid -
loleaut32 -lole32"
❑Click OK
Here is a sample program to test it's working or not. sample.cpp
#include<graphics.h>
main() {
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
getch();
closegraph();
}
If you get following screen then graphics.h is working
Initializing Graphics Mode
❏ The initgraph function is used to switch the output from text mode to
graphics mode
❏ The initgraph function takes three arguments
❏ Syntax: –
initgraph(&graphics_driver,&graphics_mode,Path _to_driver);
❏ Example:
Initial Graphics
Mode
Closing Graphics Mode
closegraph();
Some Functions in
“graphics.h”
line()
❏ line function is used to draw a line from a point(x1,y1) to
point(x2,y2)
❏ Syntax :-
❏ Remarks
➔ line draws a line from (x1, y1) to (x2, y2) using the current
color
circle()
❏ Circle function is used to draw a circle with center (x,y) and third
parameter specifies the radius of the circle.
❏ Syntax :-