Setviewport() Function

setviewport() function will create a new view port for the graphics output.


void setviewport(int left, int top, int right, int bottom, int clip);
  • First forr parameters indicate the top-left and bottom right corners of the viewport on the screen. The last parameter clip determines whether drawings are clipped (truncated) at the current viewport boundaries. If clip is nonzero, all drawings will be clipped to the current viewport.
  • For better understanding go through the program:





void main()


int gd=DETECT, gm,bkcolor;

char a[50];

initgraph(&gd,&gm," ");

outtextxy(10,10,"Rectangle in default view port:");



outtextxy(10,10,"Rectangle in new view port:");





The above program will set the new viewport for the graphics output with the help of setviewport() function. Firstly it will display a message and rectangle at default view port then it will define a new view port with top-left corner 70,400) and right bottom corner (70,400). Then again it will display a message and a rectangle in new viewport as given below in the output.


c graphics