answersLogoWhite

0

#include<GL/glut.h>

float x1,x2,x3,x4,y1,y2,y3,y4;

void draw_pixel(int x,int y)

{

glColor3f(0.5,0.0,1.0);

glPointSize(0.5);

glBegin(GL_POINTS);

glVertex2i(x,y);

glEnd();

}

void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)

{

float temp,x,mx;

int i;

if(y1>y2)

{

temp=x1,x1=x2,x2=temp;

temp=y1,y1=y2,y2=temp;

}

if(y1==y2)

mx=x2-x1;

else

mx=(x2-x1)/(y2-y1);

x=x1;

for(i=int(y1);i<=(int)y2;i++)

{

if(x<(float)le[i]) le[i]=(int)x;

if(x>(float)re[i]) re[i]=(int)x;

x+=mx;

}

}

void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)

{

int le[500],re[500],i,j;

for(i=0;i<500;i++)

le[i]=500,re[i]=0;

edgedetect(x1,y1,x2,y2,le,re);

edgedetect(x2,y2,x3,y3,le,re);

edgedetect(x3,y3,x4,y4,le,re);

edgedetect(x4,y4,x1,y1,le,re);

for(j=0;j<500;j++)

{

if(le[j]<=re[j])

for(i=le[j];i<re[j];i++)

draw_pixel(i,j);

}

}

void display()

{

x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;

y3=400.0;x4=350.0;y4=300.0;

glBegin(GL_TRIANGLES);

glVertex2f(x1,y1);

glVertex2f(x2,y2);

glVertex2f(x3,y3);

glVertex2f(x4,y4);

glEnd();

scanfill(x1,y1,x2,y2,x3,y3,x4,y4);

glFlush();

}

void init()

{

glClearColor(1.0,1.0,1.0,1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0,499.0,0.0,499.0);

}

void main(int argc,char **argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(500,500);

glutCreateWindow("scanline");

glutDisplayFunc(display);

init();

glutMainLoop();

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Difference between boundary fill algorithm and scanline polygon fill algorithm?

in scan line polygon fill, each can line crossing a polygon, the area fill algorithm locates the intersection point of the scan line with the polygon edges. These intersection points are then stored from left to right and the corresponding frame buffer positions between each intersection painr are set to the specified fill color. In boundary fill, approach to area filling is to start at a point inside a region and paint the interior outward toward and the boundary.


Compare scanline polygon fill with the boundary fill algorithm?

in scan line polygon fill, each can line crossing a polygon, the area fill algorithm locates the intersection point of the scan line with the polygon edges. These intersection points are then stored from left to right and the corresponding frame buffer positions between each intersection painr are set to the specified fill color.In boundary fill, approach to area filling is to start at a point inside a region and paint the interior outward toward and the boundary.


How do you overcome limitations of stacks in polygon filling?

You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.


Device an algorithm for weiler-atherton polygon clipping where the clipping window can be any specified polygon?

Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon


Compare the scan line polygon fill with the boundary fill algorithm?

in scan line polygon fill, each can line crossing a polygon, the area fill algorithm locates the intersection point of the scan line with the polygon edges. These intersection points are then stored from left to right and the corresponding frame buffer positions between each intersection painr are set to the specified fill color. In boundary fill, approach to area filling is to start at a point inside a region and paint the interior outward toward and the boundary.


How do you calculate the minimum bounding box of a convex polygon?

With the two rotating calipers algorithm: http://cgm.cs.mcgill.ca/~orm/rotcal.html


How do you write a function in Python to calculate the perimeter of a regular polygon of N sides and use that to approximate Pi by increasing N until Pi?

You can find a description of the algorithm in the Wikipedia article titled "Liu Hui's &Iuml;&euro; algorithm".


What is a polygon with equal sides and angles is a what polygon?

it seems to me that the only polygon of your description is a square


Types of polygons?

A type of polygon is a rhombusial polygon, trysectalnict polygon, and a equilateral polygon.


Is a traingle a regular polygon or a polygon?

A triangle (not traingle) is a polygon. It can be a regular polygon but need not be.


Is and arrow a polygon?

an arrow is or isn't a polygon?


Polygon A is a square. Polygon B has 4 more sides than polygon A. What type of polygon is B?

Polygon B is an octagon.