9
9
h>
float x1=200,y1=200,x2=100,y2=300,x3=200,y3=400,x4=300,y4=300;
float le[500],re[500];
int filled = 0;
x=x1;
for(y=y1;y<=y2;y++)
{
if(x<le[y])
{
le[y]=x;
}
if(x>re[y])
{
re[y]=x;
}
x = x + mx;
}
}
void scanfill()
{
int x,y;
glColor3f(1,0,0);
glPointSize(1); //Vary Point Size
glBegin(GL_POINTS);
for(y=0;y<500;y++)
{
for(x=le[y];x<=re[y];x++)
{
glVertex2f(x,y);
}
}
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1,1,1,0);
if(filled==0)
{
glColor3f(0,0,1); //include each vertex of polygon to be filled
glBegin(GL_LINE_LOOP);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glVertex2f(x3,y3);
glVertex2f(x4,y4);
glEnd();
}
else
{
scanfill();
}
glFlush();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,500,0,500);
}
createMenu();
init();
glutMainLoop();
}