1. Preface
The drawing of Delphi graphics can be completed between glBegin() and glEnd(). The drawing frame code can use the initialization code of OpenGL2d drawing under Delphi. For specific content, please refer to this site //www.VeVB.COm/article/52141.htm . The modified part is the content of the Draw function.
2. Draw points
Use the glPointSize function to specify the diameter of the rasterized points. The default is 1.0, which only works under GL_POINTS. We will study anti-aliasing and other functions later. Use glBegin(GL_POINTS) to tell OpenGL to draw points. The parameter GL_POINTS represents points, and there are other parameters, such as drawing lines GL_LINES, etc. For details, please refer to the source code of the OpenGL unit. The glBegin() and glEnd() functions are described as follows:
Function prototype:
void glBegin(GLenum mode)
void glEnd(void)
Parameter description:
mode: the type of primitive to be created. Can be the following values
GL_POINTS: Process each vertex as a point. Vertex n defines point n, and a total of N points are drawn.
GL_LINES: Treat each vertex as an independent line segment. A total of n line segments are defined between vertices 2n-1 and 2n, and a total of N/2 line segments are drawn.
GL_LINE_STRIP: Draw a set of line segments connected in sequence from the first vertex to the last vertex. The n and n+1 vertices define line segment n. A total of n-1 line segments are drawn.
GL_LINE_LOOP: Draw a set of line segments connected in sequence from the first vertex to the last vertex, and then the last vertex is connected to the first vertex. The nth and n+1 vertices define line segment n, and a total of n line segments are drawn.
GL_TRIANGLES: Treat each vertex as an independent triangle. Vertices 3n-2, 3n-1 and 3n define the n-th triangle, and a total of N/3 triangles are drawn.
GL_TRIANGLE_STRIP: Draw a set of connected triangles. For an odd number n, vertices n, n+1 and n+2 define the n-th triangle; for an even number n, vertices n+1, n and n+2 define the n-th triangle. A total of N-2 triangles are drawn.
GL_TRIANGLE_FAN: Draw a set of connected triangles. The triangle is determined by the first vertex and the subsequent vertices. Vertices 1, n+1 and n+2 define the n-th triangle. A total of N-2 triangles are drawn.
GL_QUADS: Draws a separate set of quadrilaterals consisting of four vertices. Vertices 4n-3, 4n-2, 4n-1 and 4n define the nth quadrilateral. Draw a total of N/4 quadrilaterals
GL_QUAD_STRIP: Draws a set of connected quadrilaterals. Each quadrilateral is defined by a pair of vertices followed by a given pair of vertices. Vertices 2n-1, 2n, 2n+2 and 2n+1 define the n-th quadrilateral, and a total of N/2-1 quadrilaterals are drawn.
GL_POLYGON: Draw a convex polygon. Vertices 1 to n define this polygon.
Function description:
The glBegin and glEnd functions define the fixed-point definition of one or more groups of primitives.
The source code to implement drawing points is as follows:
procedure TForm1.Draw;begin // Clear the buffer glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Set the point size, it cannot be between glBegin and glEnd glPointSize(10); glBegin(GL_POINTS); // Draw points // Set the point Color glColor3f(1, 0, 0); // Draw points glVertex2f(50, 50); glColor3f(0, 1, 0); glVertex2f(100, 50); glColor3f(0, 0, 1); glVertex2f(150, 50); glEnd; SwapBuffers(FDC); // Swap the contents of the double buffer, which copies the newly drawn graphics to the screen. end;
glColor3f() is used to draw the color of the point, glVertex2f draws the position of the point.
Click here to download the complete code