A. Straight line point painting mode: That is, do not completely fill all the pixels to draw a straight line, but in the form of a point painting, spaced to draw a line
First enable PIP mode:
Glenable (gl_line_stipple);
Then customize to create your own PIP mode
Gllinestipple (gllint factor,glushort pattern);
Where the first parameter factor is a multiplication factor, the second parameter pattern is a custom PIP pattern: A 16-bit value, each bit indicating that part of a segment is open or closed, and 16-based, for example: 0x5555
Example of a straight-line pip:
//STIPPLE.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<GL\glut.h>voidInit () {Glclearcolor (0.0f,0.0f,0.0f,0.0f);}voidMydisplay () {glclear (gl_color_buffer_bit); Glint Factor=1; Glushort pattern=0x5555; Glfloat y; Glenable (gl_line_stipple); glcolor3f (0.0,1.0f,0.0f); for(y =-80.0f; Y <80.0f; y+=20.0f) {gllinestipple (Factor,pattern); Glbegin (Gl_lines); GLVERTEX2F (-80.0f, y); GLVERTEX2F (80.0, y); Factor++; Glend (); } glutswapbuffers ();}voidChangesize (intWinth) { if(h==0) {h=1; } glviewport (0,0, w,h); Glmatrixmode (gl_projection); Glloadidentity (); if(w<=h) {gluortho2d (-100.0,100.0,-100.0* (glfloat) h/(glfloat) W,100.0* (glfloat) h/(Glfloat) w); } Else{gluortho2d (-100.0* (Glfloat) w/(glfloat) H,100.0* (Glfloat) w/(glfloat) h,-100.0,100.0); } glmatrixmode (Gl_modelview); Glloadidentity (); }intMainintargcChar**argv) {Glutinit (&argc,argv); Glutinitdisplaymode (Glut_rgb|glut_double); Glutinitwindowposition ( -, -); Glutinitwindowsize ( -, -); Glutcreatewindow ("Line_stipple"); Init (); Glutdisplayfunc (Mydisplay); Glutreshapefunc (changesize); Glutmainloop ();}
Drawing graphics and 3D enhancement techniques (ii)----Point drawing of straight line elements