Computer Graphics (ii) OUTPUT elements _2_ OpenGL line function

Source: Internet
Author: User
Tags polyline

OpenGL Draw Line function

A graphics package typically provides a function that describes one or more line segments, where each line segment consists of two endpoint coordinate bits defined. In OpenGL, as with selecting a point location, we use the Glvertex function to select the coordinate position of a single endpoint. We use a pair of glbegin/g1end to introduce a string of endpoint positions. There are three OpenGL symbol constants that you can use to specify how to connect the end position of this string to a set of straight segments. By default, each symbol constant displays a solid white line.

use the element line constant Gl_lines to connect each pair of adjacent endpoints and get a set of straight segments. Typically, this results in a set of non-connected segments, unless some coordinate positions are repeated. If only one endpoint is described, nothing will be displayed if the endpoint listedthe number is odd and the last one is not processed. For example, if we have 5 coordinate positions, labeled P1 to P5, each with twodimension array is represented, the following program can generate Figure 3.4 (a).
Glbegin (gl_lines);    Glvertex2iv (p1);    Glvertex2iv (p2);    Glvertex2iv (p3);    Glvertex2iv (p4);    Glvertex2iv (p5); G1end ();

In this way, we get a straight segment between the first and second coordinate positions and another straight segment between the third and fourth places. at this point, the specified number of end points is odd, so the last coordinate position is ignored.
using OpenGL's entity constants Gl_line_strip, we can get Polylines (polyline). At this point, the display froma set of line-and-end lines between the first endpoint and the last endpoint. The first line segment is between the first and second endpointsdisplay; The second segment is displayed between the second and third endpoints, and sequentially until the last endpoint. If weat least two coordinate locations are not listed and nothing is displayed. Using the 5 coordinate positions in the previous example, we display the following programFigure 3.4 (b).
Glbegin  (gl_line_strip);    Glvertex2iv (p1);    Glvertex2iv (p2);    Glvertex2iv (p3);    Glvertex2iv (P4};    G1vertex2iv (p5); Glend ();

The third OpenGL entity constant is the gl_line_loop that generates a closed polyline. It is added on top of the previous polylineA straight line segment, so the last endpoint in the polyline sequence is connected to the first endpoint. Figure 3.4 (c) gives the use of this selectionthe display of the item.
Glbegin (gl_line_loop);    Glvertex2iv (p1);    Glvertex2iv (p2);    Glvertex2iv (p3);    G1vertex2iv (p4);    Glvertex2iv (p5); G1end ();


as mentioned earlier, the graphics part described in the world coordinate system is ultimately mapped to the coordinate systems of the output device. Then a few of the information in the figure is scanned for conversion to pixel locations. In the next section, we will see a scanning conversion algorithm that implements the OpenGL line function.

Computer Graphics (ii) OUTPUT elements _2_ OpenGL line function

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.