1. Foreword:
The method of drawing quadrilaterals in Delphi is basically the same as the previous text codes. The difference lies in the parameter "GL_QUADS" of glBegin(). The drawing framework code can use the code in OpenGL2d drawing initialization under Delphi, the address is //www.VeVB.COm/article/52141.htm. The modified part is the content of the Draw function.
2. How to draw a quadrilateral:
Using GL_QUADS: Draws a separate set of quads consisting of four vertices. Vertices 4n-3, 4n-2, 4n-1 and 4n define the nth quadrilateral. Draw a total of N/4 quadrilaterals. Learning to draw quadrilaterals here is to prepare for drawing bitmaps.
Set color:
glColor3f(1, 0.5, 0); You can set the color of the quadrilateral. The parameters are three parts, which are the values of R, G, and B. The range is 0 to 1, 1 means 255, and 0.5 is shown in 128. Special attention is needed here!
Set the points of the quadrilateral:
glVertex2f(nleft, ntop); nleft and ntop represent the pixel position of the quadrilateral point on the window. The position of each point needs to be set clockwise or counterclockwise.
The code is as follows:
procedure TForm1.Draw;var l, t, w: Integer;begin // Clear the buffer glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); // Set the color of the quadrilateral glColor3f(1, 0.5, 0); // Draw the first polygon l := 10; t := 10; w := 64; glBegin(GL_QUADS); glVertex2f(l, t); glVertex2f(l + w, t); glVertex2f(l + w, t + w); glVertex2f(l, t + w); glEnd(); // Draw The second polygon l := 80; t := 10; glColor3f(0, 0.5, 0); glBegin(GL_QUADS); glVertex2f(l, t); glVertex2f(l + w, t + w); glVertex2f(l + w, t); glVertex2f(l, t + w); glEnd(); SwapBuffers(FDC); //Swap the contents of the double buffer, which will copy the graphics just drawn to the screen. end;
Click here to download the complete code