The method of drawing line opengl2d under Delphi _delphi

Source: Internet
Author: User

First, the foreword:

The Delphi method is basically the same as the point of drawing. The difference is in the Glbegin () parameter. the frame code drawn can refer to the code in opengl2d drawing initialization under Delphi, and the address is http://www.jb51.net/article/52141.htm. The modified part is the content of the Draw function.

Second, draw the line step:

Gl_lines: Each vertex as a separate segment, vertex 2n-1 and 2n have a total of N to define a line of lines, a total of N/2 line line
Gl_line_strip: Draws a group of segments that are connected sequentially from the first vertex to the last vertex, and the nth and n+1 vertices define the segment N, drawing a total of n-1 line segments
Gl_line_loop: Draws a set of segments that are connected sequentially from the first vertex to the last vertex, then the last vertex is connected to the first vertex, and the nth and n+1 vertices define the segment N and draw n a total of

Drawing lines may use the following functions:

Gllinewidth () Set line width
Glshademodel () set color transition mode
glcolor3f () set line Color

Procedure Tform1.draw;
Begin
Empty buffer
Glclear (Gl_color_buffer_bit or gl_depth_buffer_bit);
-----------Gl_lines-----------
Set line width
Gllinewidth (5);
Gradual discoloration between two points
Glshademodel (Gl_smooth);
Glbegin (Gl_lines); Draw Line
Set the color of the start line
glcolor3f (1, 0, 0);
Draw Start point
GLVERTEX2F (50, 50);
Set the color of the end point line
glcolor3f (0, 0, 1);
Painting end point
GLVERTEX2F (200, 200);
Glend;
Same color between two points
Glshademodel (Gl_flat);
Glbegin (Gl_lines);
glcolor3f (0, 1, 0);
GLVERTEX2F (200, 50);
glcolor3f (1, 1, 0);
GLVERTEX2F (50, 200);
Glend;
-----------Gl_line_loop-----------
Three point closed loops form a triangular glshademodel (Gl_smooth); Doesn't work
Gllinewidth (1);
Glbegin (Gl_line_loop);
glcolor3f (0, 0, 1);
GLVERTEX2F (250, 50);
GLVERTEX2F (250, 200);
GLVERTEX2F (280, 150);
Glend;
-----------Gl_line_strip-----------
Multi-point polyline Glshademodel (Gl_smooth); Doesn't work
Gllinewidth (1);
Glbegin (Gl_line_strip);
glcolor3f (1, 0, 255);
GLVERTEX2F (350, 50);
GLVERTEX2F (400, 200);
GLVERTEX2F (480, 150);
GLVERTEX2F (490, 60);
Glend;
Swapbuffers (FDC); Swap double buffer content, which will reprint the newly-drawn graphic to the screen.
End

You can see the first X line color gradient, which OpenGL by default is this style. OpenGL provides a function Glshademodel to determine how to handle this different color.

Glshademodel (Gl_smooth); Smooth way, this is also the default mode of OpenGL processing, to achieve the effect of color gradient
Glshademodel (gl_flat);  Monochrome method, the color of a segment is based on the color of a vertex, determined by the specific implementation. In order to avoid uncertainty, you should try to use the same color in the polygon

After testing found that in the Gl_line_loop and Gl_line_strip style, the gradient effect is invalid! Specific reasons need to be further identified.

In addition, OpenGL provides anti-aliasing and functions as

Glenable (Gl_line_smooth); Enable
Glhint (gl_line_smooth,gl_nicest);
Gldisable (Gl_line_smooth); Shut down

After use, the effect of anti-aliasing is not obvious. Further research remains to be done.

Complete code point this download

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.