Drawing graphics and 3D enhancement techniques (ii)----Point drawing of straight line elements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.