"Graphic Science" experiment Three: DDA algorithm draw straight line

Source: Internet
Author: User
Tags set background

Development Environment:

Vc++6.0,opengl

Experimental content:

Use the DDA algorithm to draw a straight line.

Experimental Results:

Code:
1#include <gl/glut.h>2#include <math.h>3 4 #defineWIDTH 500//window Width5 #defineHEIGHT 500//Window Height6 7 #defineDRAWLINE1 Ddaline (100,200,200,100);//Draw a line8 #defineDRAWLINE2 Ddaline (200,100,450,400);//Draw a line9 Ten #pragmaComment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "")//Canceling the console One  A voidInit ()//Initialize - { -Glclearcolor (1.0f,1.0f,1.0f,1.0f);//Set background color, completely opaque theGLCOLOR3F (1.0f,0.0f,0.0f);//Set Brush Color -  -Glmatrixmode (gl_projection);//Set Projection -Gluortho2d (0.0, WIDTH,0.0, HEIGHT);//Setting the projection area + } -  + voidDdaline (intX0,intY0,intX1,intY1)//DDA algorithm draw line A { at     intdx,dy,eps1,i; -     floatX,y,xincre,yincre; -DX = x1-x0; -DY = y1-y0; -x = X0,y =y0; -     if(ABS (DX) >abs (DY)) inEPS1 =ABS (DX); -     Else  toEPS1 =abs (DY); +Xincre = (float) DX/float(EPS1); -Yincre = (float) dy/float(EPS1); the      for(i=0; i<=eps1;i++){ * Glbegin (gl_points); $Glvertex2i (int(x+0.5),int(y+0.5));Panax Notoginseng glend (); -x+=Xincre; they+=Yincre; +     } A } the  + voidDisplay ()//Display Functions - { $Glclear (Gl_color_buffer_bit);//Empty the color stack $  - DRAWLINE1 - DRAWLINE2 the  -Glflush ();//emptying buffer DirectivesWuyi } the  - intMainintargcChar**argv) Wu { -Glutinit (&argc,argv); AboutGlutinitdisplaymode (Glut_single | GLUT_RGB);//Initialize display mode $Glutinitwindowsize (Width,height);//Set Window Size -Glutinitwindowposition ( $, -);//Set Window Position -Glutcreatewindow ("Draw a line");//Create Window -  AGlutdisplayfunc (Display);//Registering display functions +Init ();//Initialize theGlutmainloop ();//Enter program Loop -     return 0; $}

freecode:www.cnblogs.com/yym2013

"Graphic Science" experiment Three: DDA algorithm draw straight line

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.