1 o'clock:
void TestPoint() { // The size of the point defaults to one pixel, and the size of a point can be set by the following function glPointSize( 50.0f ); glBegin(GL_POINTS); glVertex2f(0, 0); glVertex2f(0.5f, 0.5f); glEnd(); }
2. Line:
void TestLine() { // Set the width of the line glLineWidth( 500.0f ); glBegin(GL_LINES); glVertex2f(0, 0); glVertex2f(0.5f, 0.5f); glEnd(); }
3. Dotted line:
// Draw a dotted line void TestLineStiple() { // Enable dotted line mode, use glDisable(GL_LINE_STIPPLE) to turn off dotted line mode glEnable(GL_LINE_STIPPLE); // Set the width of the line glLineWidth( 500.0f ); // Set the style of the dotted line // Parameter 1: the number of points to be drawn // Parameter 2: It is a sequence of 1 and 0 with a length of 16, starting from the lowest bit, if it is 1, the straight line The factor points that should be drawn next will be drawn as real; if it is 0, the factor points that should be drawn next on the line will be drawn as virtual. glLineStipple( 2 , 0x0F0F ); glBegin(GL_LINES); glVertex2f(0, 0); glVertex2f(0.5f, 0.5f); glEnd();
4. Polygon:
1> The two sides of the polygon and how to draw it:
The polygon has two faces, and each face can be set to a different drawing mode: fill (the default drawing mode), only draw edge outlines, and only draw vertices.
glPolygonMode(GL_FRONT, GL_FILL); // set front as fill mode
glPolygonMode(GL_BACK, GL_LINE); // Set the back side as the edge drawing method
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); // Set both sides to be vertex drawing
2>General convention, counterclockwise is positive, clockwise is negative,
The concepts of "heads" and "tails" can be swapped with the glFrontFace function.
glFrontFace(GL_CCW); // Set the CCW direction to "front", CCW is CounterClockWise, counterclockwise
glFrontFace(GL_CW); // Set the CW direction to "Front", CW is ClockWise, clockwise
void TestPolygon() { // glPolygonMode(GL_FRONT, GL_FILL); // Set the front to fill mode // glPolygonMode(GL_BACK, GL_LINE); // Set the reverse side as the edge drawing method // glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); // Set both sides to be vertex drawing glPolygonMode(GL_FRONT, GL_FILL); // Set front to fill mode glPolygonMode(GL_BACK, GL_LINE); // Set back to line mode glFrontFace(GL_CCW) ; // Set the counterclockwise direction to the front glBegin(GL_POLYGON); // Draw a square counterclockwise, at the bottom left glVertex2f( - 0.5f , - 0.5f ); glVertex2f(0.0f, -0.5f); glVertex2f(0.0f, 0.0f); glVertex2f(-0.5f, 0.0f); glEnd(); glBegin(GL_POLYGON); // Draw a square clockwise at the top right glVertex2f( 0.0f , 0.0f ); glVertex2f(0.0f, 0.5f); glVertex2f(0.5f, 0.5f); glVertex2f(0.5f, 0.0f); glEnd(); glFlush(); }
3> Cull polygons:
glEnable(GL_CULL_FACE) enables culling
glDisable(GL_CULL_FACE) disable culling
The parameters of glCullFace can be GL_FRONT, GL_BACK, GL_FRONT_AND_BACK, which means to remove the front, back, and front and back polygons respectively.
Note: The culling function only affects polygons, not points and lines. For example, with glCullFace(GL_FRONT_AND_BACK), all polygons will be culled, so only points and lines are visible.