First, the experimental purpose and requirements 1. understand basic graphic elements rasterization principle, master a basic graphic element rasterization algorithm, using OpenGL implementation of linear rasterization DDA algorithm. Second, the experimental content and the main step code (1) According to the given linear rasterization model source program, write out the DDA algorithm, compile and run on the computer, output the correct result; (2) Understand and use OpenGL's command to generate a line to verify the program's running results. Main Steps Code: (1) DDA algorithm for linear rasterization: Void linedda (int x1,int y1,int x2,int y2) { float x, y, dx, dy; int k, I; if (ABS (X2-X1) >=abs (y2-y1)) { k=abs (x2-x1); } else { k=abs (y2-y1); } dx= ( float) (x2-x1)/k; dy= (float) (y2-y1)/k; x= (float) (x1); y= (float) (y1); for (i=0;i<k; i++) { glpointsize (2); glBegin (gl_points); glcolor3f ( 1.0f, 0.0f, 0.0f); glvertex2i ((int) (x+0.5), (int) (y+0.5)); glend (); x+=dx; y+ =dy; } }
2. According to the model procedure, this is used as the basis to transform it into a round rasterization algorithm, write the relevant code. (Just write the part of the Bresenham algorithm to generate the circle) A: (1) The Bresenham algorithm generates a circle void plot_circle_points (int xc,int yc,int x,int y) { Glbegin (gl_points); glvertex3f (xc+x,yc+y,0); glvertex3f (xc-x,yc+y,0); glvertex3f (xc+x,yc-y,0); glVertex3f ( xc-x,yc-y,0); glvertex3f (xc+y,yc+x,0); glVertex3f ( xc-y,yc+x,0); glvertex3f (xc+y,yc-x,0); glVertex3f ( xc-y,yc-x,0); glend (); }void drawcircle (int xc,int yc,int RADIUS) { int x,y,p; x=0; y=radius; p=3-2*radius; glclear (gl_color_buffer_bit); Glbegin (gl_points); while (x<y) { plot_circle_points (xc,yc,x,y); if (p<0) p=p+4*x+6; else { p=p+4* (x-y) +10; y-=1; } x+=1; } if (x==y) Plot_cIrcle_points (xc,yc,x,y);}
Experimental two-line generation algorithm