Setviewport() Function

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

Declaration

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:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm,bkcolor;

char a[50];

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

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

rectangle(10,20,60,40);

setviewport(70,70,400,400,1);

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

rectangle(10,20,60,40);

getch();

closegraph();

}

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.

Output

c graphics