Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

MCA 4th sem /MCA 406 / CRNo.

186008 / URNo :1811443 Page 1


10)Draw figure using DDA line algorithm
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void dda(int x1,int y1,int x2,int y2)
{
float dx,dy,len,xi,yi,i=1;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>=abs(dy))
len=abs(dx);
else
len=abs(dy);
xi=x1+0.5;
yi=y1+0.5;
putpixel(xi,yi,WHITE);
dx=(dx)/len;
dy=(dy)/len;
while(i<=len)
{
xi=xi+dx;
yi=yi+dy;
putpixel(xi,yi,WHITE);
i++;
}
}
void main()
{
int gdriver =DETECT,gmode;
initgraph(&gdriver,&gmode,"");
dda(100,100,300,100);
dda(100,100,200,300);
dda(300,100,200,300);
dda(100,270,200,50);
dda(300,270,200,50);
dda(100,270,300,270);
getch();
closegraph();
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 2
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 3
11) Draw a rectangle using Bresenhams algorithm for line.

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gdriver =DETECT,gmode;
int x1,y1,x2,y2,c=15;

initgraph(&gdriver,&gmode,"");
line(100,100,400,100);
line(100,100,100,300);
line(100,300,400,300);
line(400,100,400,300);
getch();
closegraph();
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 4
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 5
12) Draw a pentagon using DDA algorithm for line

#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void dda(int x1,int y1,int x2,int y2)
{
float dx,dy,len,xi,yi,i=1;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>=abs(dy))
len=abs(dx);
else
len=abs(dy);
xi=x1+0.5;
yi=y1+0.5;
putpixel(xi,yi,WHITE);
dx=(dx)/len;
dy=(dy)/len;
while(i<=len)
{
xi=xi+dx;
yi=yi+dy;
putpixel(xi,yi,WHITE);
i++;
}
}
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
dda(50,150,100,100);
dda(100,100,150,150);
dda(150,150,125,200);
dda(125,200,75,200);
dda(75,200,50,150);

getch();
closegraph();
return 0;
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 6
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 7
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 8
13) Implement a circle using direct equation of the circle

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void plotcircle(int,int,int,int);

void main()
{

int gd = DETECT, gm;


int xc,yc,x,y,xend,r,d;
initgraph(&gd, &gm, "");
printf("Enter xc, yc and r:");
scanf("%d %d %d",&xc,&yc,&r);
x=0;
xend=r/sqrt(2);
plotcircle(xc,yc,x,y);
while(x<xend)
{
x=x+1;
y=sqrt((r*r)-(x*x));
plotcircle(xc,yc,x,y);
}
getch();
}

void plotcircle(int xc,int yc,int x,int y)


{
putpixel(xc+x,yc+y,2);
putpixel(xc-x,yc+y,2);
putpixel(xc+x,yc-y,2);
putpixel(xc+y,yc+x,2);
putpixel(xc-y,yc-x,2);
putpixel(xc-y,yc+x,2);
putpixel(xc+y,yc-x,2);
putpixel(xc-x,yc-y,2);

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 9
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 10
14)Draw an ellipse using trigonometric functions

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
double a=100,b=30,x,y,theta;
initgraph(&gd,&gm," ");
cleardevice();
for(theta =0;theta<=360;theta++)
{
x = 200+a*cos((theta*3.141)/180);
y = 200+b*sin((theta*3.141)/180);
putpixel(x,y,YELLOW);

}
getch();
closegraph();
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 11
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 12
15) Implement Mid Point Algorithm for circle

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void mcircle(int xc,int yc,int r);
void drawcircle(int xc,int yc,int x,int y);
void main()
{
int gdriver =DETECT,gmode;
initgraph(&gdriver,&gmode,"");
int xc,yc,r;
xc=200;
yc=200;
r= 80;
mcircle(xc,yc,r);
getch();
closegraph();
}
void mcircle(int xc,int yc,int r)
{
int x,y,p;
x=0;
y=r;
p=1-r;
while(x < y)
{
drawcircle(xc,yc,x,y);
if (p<0)
{
p=p+2*x+3;
x=x+1;
}
else
{
p=p+2*x-2*y+5;
x=x+1;
y=y-1;
}
}
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 13
void drawcircle(int xc,int yc,int x,int y)
{
int c = 15;
putpixel(xc+x,yc+y,c);
putpixel(xc+x,yc-y,c);
putpixel(xc-x,yc-y,c);
putpixel(xc-x,yc+y,c);
putpixel(xc+y,yc+x,c);
putpixel(xc+y,yc-x,c);
putpixel(xc-y,yc-x,c);
putpixel(xc-y,yc+x,c);
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 14
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 15
16)Use the mouse functionality in c++

#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
union REGS in,out;
int callmouse()
{
in.x.ax=1;
int86(51,&in,&out);
return 1;
}

void mouseposi(int &xpos,int &ypos,int &click)


{
in.x.ax=3;
int86(51,&in,&out);
click=out.x.bx;
xpos=out.x.cx;
ypos=out.x.dx;
}

int mousehide()
{
in.x.ax=2;
int86(51,&in,&out);
return 1;
}

void setposi(int &xpos,int &ypos)


{
in.x.ax=4;
int86(51,&in,&out);
in.x.cx=xpos;
in.x.dx=ypos;
}

int main()
{
int x,y,cl,a,b;
clrscr();
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 16
int g=DETECT,m;
initgraph(&g,&m,"c:\tc\bgi");
a=100;
b=400;
setposi(a,b);
callmouse();
do
{
mouseposi(x,y,cl);
gotoxy(10,9);
printf("\n\t Mouse Position is: %3d,%3d",x,y);
printf("\n\t Click: %d",cl);
printf("\n\t Press any key to hide the mouse");
}
while(!kbhit());
getch();
mousehide();
printf("\n\t Press any key to exit");
getch();
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 17
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 18
17)To draw 3D object using Palettes

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
int gdriver = VGA, gmode = VGAHI, errorcode;
struct palettetype pal;
int i, ht, y, xmax;

/* initialize graphics and local variables */


initgraph(&gdriver, &gmode, "");

/* read result of initialization */


errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

/* grab a copy of the palette */


getpalette(&pal);

/* create gray scale */


for (i=0; i<pal.size; i++)
setrgbpalette(pal.colors[i], i*i, i*i, i*i);

setcolor(15);
rectangle(200,200,300,300);

line(200,200,350,100);
line(300,200,450,100);
line(350,100,450,100);

line(450,100, 450,200 );

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 19
line(450,200,300,300);
// setcolr(15);
setfillstyle(SOLID_FILL, 3);
floodfill(250,250,15);
setfillstyle(SOLID_FILL, 7);
floodfill(350,150,15);
setfillstyle(SOLID_FILL, 9);
floodfill(330,230,15);
/* clean up */
getch();
closegraph();
return 0;
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 20
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 21
18)Rotating a polygon

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void drawp(float v[3][3]);
void vertices(float r[3][3]);
void rotation(float r[3][3],int angle);
void multiply(float a[3][3],float b[3][3],float res[3][3]);
void draw(float d[3][3]);
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float
r[3][3],s[3][3],v[3][3],res[3][3],t[3][3],tn[3][3],res1[3][3],res2[3][3],res3[3][3],res4[3][3];
vertices(v);
drawp(v);

rotation(r,10);

multiply(v,r,res);

setcolor(5);
drawp(res);

getch();
closegraph();
}
void vertices(float v[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
}
v[i][2]=1;
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 22
v[0][0]=100;
v[0][1]=100;
v[1][0]=50;
v[1][1]=150;
v[2][0]=200;
v[2][1]=200;
}
void translate(float v[3][3],int tx,int ty)
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
if (i==j)
{ v[i][j]=1;}
}
}
v[2][0]=tx;
v[2][1]=ty;
}

void scaling(float s[3][3],int sx,int sy)


{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
s[i][j]=0;
if (i==j)
{ s[i][j]=1;}
}
}
s[0][0]=sx;
s[1][1]=sy;
}

void rotation(float r[3][3],int angle)


{
int i,j;
float th=0.0175*angle;
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 23
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
r[i][j]=0;
}
r[0][0]=cos(th);
r[0][1]=sin(th);
r[1][0]=-sin(th);
r[1][1]=cos(th);
r[2][2]=1;
}
void multiply(float a[3][3],float b[3][3],float res[3][3])
{
int i, j, k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
res[i][j] = 0;
for(k=0;k<3;k++)
res[i][j] = res[i][j] + (a[i][k] * b[k][j] );
}
}

void draw(float d[3][3])


{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}
void drawp(float v[3][3])
{
int i,j;
moveto(v[0][0], v[0][1]);
for(i=1;i<3;i++)
lineto(v[i][0], v[i][1]);
lineto(v[0][0], v[0][1]);
}
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 24
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 25
19) Rotating a polygon w.r.t fixed point

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void dispmat(float v[3][3]);
void vertices(float v[3][3]);
void rotate(float rt[3][3], int th);
void mult(float a[3][3],float b[3][3], float c[3][3]);
void drawp(float v[3][3]);

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float v[3][3],r[3][3],rt[3][3];
setcolor(5);
vertices(v);
drawp(v);
rotate(rt,10);
mult(v,rt,r);
getch();
setcolor(4);
drawp(r);
getch();
closegraph();
}

void vertices(float v[3][3])


{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
v[i][j] = 0;
v[i][2] = 1;
}
v[0][0] = 300;

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 26
v[0][1] = 300;
v[1][0] = 250;
v[1][1] = 350;
v[2][0] = 400;
v[2][1] = 300;
}

void dispmat(float v[3][3])


{
int i,j;
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++) printf("\n ",v[i][j]);
}
}

void rotate(float rt[3][3], int th)


{
int i,j;
float rth;
rth = 0.0175 * th;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
rt[i][j] = 0;
if (i==j) rt[i][i] = 1;
}
rt[0][0] = cos(rth);
rt[0][1] = sin(rth);
rt[1][0] = -sin(rth);
rt[1][1] = cos(rth);
}

void mult(float a[3][3],float b[3][3], float c[3][3])


{
int i, j, k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
c[i][j] = 0;
for(k=0;k<3;k++)
c[i][j] = c[i][j] + (a[i][k] * b[k][j] );
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 27
}
}

void drawp(float v[3][3])


{
int i,j;
moveto(v[0][0], v[0][1]);
for(i=1;i<3;i++)
lineto(v[i][0], v[i][1]);
lineto(v[0][0], v[0][1]);
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 28
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 29
20)Scale and then rotate the polygon about origin
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void drawp(float v[3][3]);
void vertices(float r[3][3]);
void rotation(float r[3][3],int angle);
void multiply(float a[3][3],float b[3][3],float res[3][3]);
void draw(float d[3][3]);
void scaling(float s2[3][3],int sx,int sy);
void translate(float v[3][3],int tx,int ty);
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float
r[3][3],s[3][3],v[3][3],res[3][3],t[3][3],tn[3][3],res1[3][3],res2[3][3],res3[3][3],res4[3][3];
vertices(v);
drawp(v);

scaling(s,1,2);
rotation(r,10);
multiply(v,s,res);
multiply(res,r,res1);

setcolor(5);

drawp(res1);

getch();
closegraph();
}
void vertices(float v[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
}
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 30
v[i][2]=1;
}
v[0][0]=100;
v[0][1]=100;
v[1][0]=50;
v[1][1]=150;
v[2][0]=200;
v[2][1]=200;
}
void translate(float v[3][3],int tx,int ty)
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
if (i==j)
{ v[i][j]=1;}
}
}
v[2][0]=tx;
v[2][1]=ty;
}

void scaling(float s[3][3],int sx,int sy)


{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
s[i][j]=0;
if (i==j)
{ s[i][j]=1;}
}
}
s[0][0]=sx;
s[1][1]=sy;
}
void rotation(float r[3][3],int angle){
int i,j;
float th=0.0175*angle;
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 31
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
r[i][j]=0;
}
r[0][0]=cos(th);
r[0][1]=sin(th);
r[1][0]=-sin(th);
r[1][1]=cos(th);
r[2][2]=1;
}
void multiply(float a[3][3],float b[3][3],float res[3][3])
{
int i, j, k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
res[i][j] = 0;
for(k=0;k<3;k++)
res[i][j] = res[i][j] + (a[i][k] * b[k][j] );
}
}
void draw(float d[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}
void drawp(float v[3][3])
{
int i,j;
moveto(v[0][0], v[0][1]);
for(i=1;i<3;i++)
lineto(v[i][0], v[i][1]);
lineto(v[0][0], v[0][1]);
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 32
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 33
21) Scale then rotate the polygon about fixed point,

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void drawp(float v[3][3]);
void vertices(float r[3][3]);
void rotation(float r[3][3],int angle);
void multiply(float a[3][3],float b[3][3],float res[3][3]);
void draw(float d[3][3]);
void scaling(float s2[3][3],int sx,int sy);
void translate(float v[3][3],int tx,int ty);
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
float
r[3][3],s[3][3],v[3][3],res[3][3],t[3][3],tn[3][3],res1[3][3],res2[3][3],res3[3][3],res4[3][3];
vertices(v);
// cout<<"Vertics Matrix\n";
drawp(v);
// cout<<"Translate Matrix\n";
translate(t,-300,-300);
// drawp(t);
// cout<<"Negative Scaling Matrix\n";
scaling(s,-1,-2);
// drawp(s);

// cout<<"Rotation Matrix\n";
rotation(r,25);
// drawp(r);
// cout<<"Mult res1= v* -t \n ";
multiply(v,t,res);
// draw(res);
// cout<<"Mult res=res1*(-sx,-sy) \n";
multiply(res,s,res1);
// draw(res1);

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 34
// cout<<"Mult res2=res1*r \n";
multiply(res1,r,res2);
// draw(res2);

// cout<<"Scaling Matrix\n";
scaling(s,1,2);
// draw(s);

// cout<<"Mult res3=res2*(sx,sy) \n";


multiply(res2,s,res3);
// draw(res3);

// cout<<"Translate Matrix\n";
translate(t,300,300);
// draw(t);

// cout<<"Mult res4=res3*t (+v) \n";


multiply(res3,t,res4);
drawp(res4);

getch();
closegraph();
}
void vertices(float v[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
}
v[i][2]=1;
}
v[0][0]=300;
v[0][1]=300;
v[1][0]=250;
v[1][1]=350;
v[2][0]=400;
v[2][1]=300;
}
void translate(float v[3][3],int tx,int ty)
{
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 35
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
v[i][j]=0;
if (i==j)
{ v[i][j]=1;}
}
}
v[2][0]=tx;
v[2][1]=ty;
}

void scaling(float s[3][3],int sx,int sy)


{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
s[i][j]=0;
if (i==j)
{ s[i][j]=1;}
}
}
s[0][0]=sx;
s[1][1]=sy;
}

void rotation(float r[3][3],int angle)


{
int i,j;
float th=0.0175*angle;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
r[i][j]=0;
}
r[0][0]=cos(th);
r[0][1]=sin(th);
r[1][0]=-sin(th);
r[1][1]=cos(th);
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 36
r[2][2]=1;
}
void multiply(float a[3][3],float b[3][3],float res[3][3])
{
int i, j, k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
res[i][j] = 0;
for(k=0;k<3;k++)
res[i][j] = res[i][j] + (a[i][k] * b[k][j] );
}
}

void draw(float d[3][3])


{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}
void drawp(float v[3][3])
{
int i,j;
moveto(v[0][0], v[0][1]);
for(i=1;i<3;i++)
lineto(v[i][0], v[i][1]);
lineto(v[0][0], v[0][1]);
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 37
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 38
22) Implemen t Bresenhams algorithm for Circle.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
r=100;
x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if(p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);
}
getch();
closegraph();
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 39
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 40
23) Draw a polygon using OpenGl.
/*
* GL01Hello.cpp: Test OpenGL C/C++ Setup
*/
#include <windows.h> // For MS Windows
#include <GL/glut.h> // GLUT, includes glu.h and gl.h

/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer

// Draw a Red 1x1 Square centered at origin


glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 2.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();

glFlush(); // Render now


}

/* Main function: GLUT runs as a console application starting at main() */


int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}

MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 41
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 42
MCA 4th sem /MCA 406 / CRNo. 186008 / URNo :1811443 Page 43

You might also like