Experimental two-line generation algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.