Computer Graphics Experiment 1: Linear Grating DDA Algorithm Using OpenGL

Source: Internet
Author: User

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:


Related Article

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.