by default, filled polygons are drawn in solid mode. In addition, they can use a 32-bit x32-bit window-aligned PIP mode. The Glpolygonstipple () function is used to specify the point-drawing mode of a polygon.
void Glpolygonstipple (const glubyte *mask);
Defines the current PIP mode of the fill polygon. The mask parameter is a pointer to a 32x32 bitmap, which is interpreted as a mask of 0 and 1. If 1 is present in the pattern, the corresponding pixel in the polygon is drawn, and if 0 is present, the corresponding pixel in the polygon is not drawn.
Below is a demo of the dot drawing of the polygon with a demo of a little cockroach.
main.cpp//opengl_04_polygon////Created by Apple on 14/12/30.//Copyright (c) 2014 CC. All rights reserved.//#include <iostream> #include <glut/glut.h>/** * Initialize Operation */void init () {glclearcolor (0. 0f, 0.0f, 0.0f, 0.0f); Sets the shading mode, Gl_flat uses constant shading, and renders the entire entity with the color of a vertex in the entity. Glshademodel (Gl_flat);} /** * Display Drawing effect */void display () {glubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x 0x20, 0x04, 0x0C, 0x30, 0x20, 0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22, 0x 0x80, 0x01, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x 0x22, 0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30, 0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0XFC, 0xc0, 0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0XCC, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0XCC, 0x33, 0x30, 0x18, 0XCC, 0x33, 0x18, 0 X10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0 X00, 0x08}; Glubyte halftone[] = {0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0 X55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0X55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}; Clears the color buffer glclear (gl_color_buffer_bit); Set drawing color (white) glcolor3f (1.0, 1.0, 1.0); 1. Draw a rectangle (square), left GLRECTF (25.0, 25.0, 125.0, 125.0); Turn on polygon pip mode glenable (gl_polygon_stipple); 2. Draw a small strong rectangle//Xiao Qiang rectangular region 32*32 bit glpolygonstipple (fly) by PIP mode; Specifies the rectangular region where the cockroach is located GLRECTF (125.0, 25.0, 225.0, 125.0); 3. Draw a net Diagram Glpolygonstipple (halftone) by dot painting; Specifies the rectangular area where the grid map is located GLRECTF (225.0, 25.0, 325.0, 125.0); Turn off polygon pip mode gldisable (gl_polygon_stipple); Glflush ();} /** * Resize Window * * @param width Width * @param height */void reshape (int width, int height) {//Set viewport rectangle area, by default, viewport is set Glviewport (0, 0, (Glsizei) width, (glsizei) height) for the entire pixel rectangle that occupies the open window; The subsequent matrix operation Glmatrixmode (gl_projection) is applied to the projection matrix; is equal to the previous matrix transformation caused the change of the stack top matrix back to bits, set as the unit matrix! is equal to the effect of the previous matrix transformation. Glloadidentity (); Specify 2D cropping coordinate system, Naer and far use default values-1 and 1 gluortho2d (0.0, (gldouble) width, 0.0, (gldouble) height);} /** * Keyboard Event Callback * * @param key keyed * @param x Width * @param y height */void keyboard (unsigned char key, int x, int y) {s Witch (key) {//esc case 27:exit (0); Break }}int Main (int argc, const char * argv[]) {//Initialize GLUT library Glutinit (&ARGC, (char**) argv); Sets the double-buffered, RGB-pixel-formatted window glutinitdisplaymode (Glut_single | GLUT_RGB); Set window size glutinitwindowsize (350, 150); Set window coordinates glutinitwindowposition (100, 100); Create Window Glutcreatewindow ("Lines"); Initialization Operation Init (); Set the display callback method Glutdisplayfunc (display); Glutreshapefunc (reshape); Glutkeyboardfunc (keyboard); Draw thread Start loop glutmainloop (); return 0;}
this article by cc original summary, if need reprint please indicate source: http://blog.csdn.net/oktears/article/details/42262187
OpenGL Learning 05_ pip mode (dot-draw polygon)