Index of this blog's computer graphics series:
Address: Index of related articles in computer graphics series (continuous update)
Reference material: Computer Graphics Machinery Industry Press, edited by Xu wenpeng.
# Include <tchar. h> # include <Gl/glut. h> # include <cstdlib> // link necessary library files # pragma comment (Lib, "opengl32.lib") # pragma comment (Lib, "glu32.lib") # pragma comment (Lib, "glu32.lib") 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 ;}} void renderscene (void) {glclear (gl_color_buffer_bit ); // draw the X axis glbegin (gl_lines); glcolor3f (0.0f, 0.0f, 0.0f); glvertex2f (-501_f, 0.0f); glvertex2f (501_f, 0.0f); glend (); // draw the y-axis glbegin (gl_lines); glcolor3f (0.0f, 0.0f, 0.0f); glvertex2f (0.0f,-501_f); glvertex2f (0.0f, 501_f); glend (); // use the DDA algorithm to draw two linedda lines (-50,-50, 50, 50); linedda (-50, 50, 50,-50); glflush ();} void changesize (glsizei W, glsizei h) {If (H = 0) {H = 1 ;}// defines the glviewport (0, 0, W, H ); glmatrixmode (gl_projection); glloadidentity (); // defines the orthogonal field of sight if (W
Experiment results: