绘制直线虚线点划线

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

static GLsizei iMode=1;

int winWidth=400,winHeight=300;

void Initial(void)

{

glClearColor(1.0f,1.0f,1.0f,1.0f);

}

void ChangeSize(int w,int h)

{

winWidth=w;

winHeight=h;

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0,winWidth,0.0,winHeight); }

void Display(void)

{

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0f,0.0f,0.0f);

if(iMode==1)

{

glBegin(GL_LINES);

glVertex2i(110,50);

glVertex2i(150,250);

glEnd();

}

if(iMode==2)

{

glEnable(GL_LINE_STIPPLE);

glLineStipple(2,0X00FF);

glBegin(GL_LINES);

glVertex2i(110,50);

glVertex2i(150,250);

glEnd();

}

if(iMode==3)

{

glEnable(GL_LINE_STIPPLE);

glLineStipple(2,0X087F);

glBegin(GL_LINES);

glVertex2i(110,50);

glVertex2i(150,250);

glEnd();

}

glutSwapBuffers();

}

void ProcessMenu(int value)//菜单函数

{

iMode=value;

glutPostRedisplay();

}

int main(int argc,char*argv[])

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(400,300);

glutInitWindowPosition(100,100);

glutCreateWindow("绘制实线、虚线、点划线");

glutCreateMenu(ProcessMenu);//菜单注册函数

glutAddMenuEntry("绘制直线",1);

glutAddMenuEntry("绘制虚线",2);

glutAddMenuEntry("绘制点划线",3);

glutAttachMenu(GLUT_RIGHT_BUTTON);//右键点开菜单栏

glutDisplayFunc(Display);

glutReshapeFunc(ChangeSize);

Initial();

glutMainLoop();

return 0;

}

相关文档
最新文档