Opengl2d plotting in Delphi (03)-Line Drawing

Source: Internet
Author: User

I. Preface

The draw line is basically the same as the draw point code. The difference is that glbegin () parameters. You can use opengl2d plotting (01)-initialization code in Delphi to draw the Framework Code. The modified part is the content of the draw function.

Ii. Draw a line

Gl_lines: each vertex is used as an independent line segment. n lines are defined between the 2n-1 and 2n vertices, and n/2 lines are drawn in total.

Gl_line_strip: Draw a group of line segments connected from the first vertex to the last vertex. The N and n + 1 vertices define the line segment N, and draw n-1 lines in total.

Gl_line_loop: draws a group of line segments connected from the first vertex to the last vertex, and then connects the last vertex to the first vertex, the N and n + 1 vertices define the line N and draw n lines in total.

The following functions may be used to draw a line:

Gllinewidth () is used to set the line width.

Glshademodel () sets the color transition mode

Glcolor3f () set the line color

Procedure tform1.draw; begin // clear the buffer glclear (buffers or cached); // ----------- gl_lines ----------- // set the line width gllinewidth (5); // gradient between two points glshademodel (gl_smooth ); glbegin (gl_lines); // set the color of the starting line glcolor3f (255, 0, 0); // draw the starting line glvertex2f (50, 50 ); // set the glcolor3f (0, 0,255) color of the last vertex line; // glvertex2f (200,200); glend; // glshademodel (gl_flat) in the same color between the two vertices ); glbegin (gl_lines); glcolo R3f (0,255, 0); glvertex2f (200, 50); glcolor3f (255,255, 0); glvertex2f (50,200); glend; // ----------- gl_line_loop ----------- // Three Point Closed Loops form a triangle glshademodel (gl_smooth); gllinewidth (1); glbegin (gl_line_loop); glcolor3f (0, 0,255 ); glvertex2f (250, 50); glvertex2f (250,200); glvertex2f (280,150); glend; // ----------- gl_line_strip ----------- // multi-point line glshademodel (gl_smooth); does not work gllinewidth (1 ); Glbegin (gl_line_strip); glcolor3f (255, 0,255); glvertex2f (350, 50); glvertex2f (400,200); glvertex2f (480,150); glvertex2f (490, 60); glend; swapbuffers (FDC); // swap the dual-buffer content, which prints the newly drawn image to the screen. End;

The effect is as follows:

We can see the color gradient of the first X-ray. OpenGL uses this style by default. OpenGL provides a function glshademodel to determine if different colors are to be processed.

Glshademodel (gl_smooth); // smooth mode, which is also the default Processing Method of OpenGL to achieve the effect of color gradient glshademodel (gl_flat); // monochrome mode, the color of a line segment is determined by the color of a vertex. To avoid uncertainty, try to use the same color in the polygon.

After the test, the gradient effect is invalid in the gl_line_loop and gl_line_strip styles !!! Is it my program? The cause is unknown.

In addition, OpenGL provides the anti-aliasing function. The function is

Glable (gl_line_smooth); // enable glhint (gl_line_smooth, gl_nicest); gldisable (gl_line_smooth); // disable

After use, it is found that the anti-tooth effect is not obvious. What's my problem? I will study it later.

 

2014-06-26 by Lin

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.