在默认情况下,填充多边形是用实心模式绘制的。此外,它们还可以使用一种32位×32位的窗口对齐的点画模式。glPolygonStipple()函数用于指定多边形的点画模式。
-
voidglPolygonStipple(constGLubyte*mask);
定义填充多边形的当前点画模式。mask参数是一个指向32×32位图的指针,后者被解释为0和1的掩码。如果模式中出现的是1,那么多边形中对应的像素就被绘制;如果出现的是0,多边形中对应的像素就不被绘制。
下面通过一个绘制小强的Demo演示一下多边形的点画。
-
-
-
-
-
-
-
-
-
#include<iostream>
-
#include<GLUT/GLUT.h>
-
-
-
-
-
voidinit(){
-
glClearColor(0.0f,0.0f,0.0f,0.0f);
-
-
glShadeModel(GL_FLAT);
-
}
-
-
-
-
-
voiddisplay(){
-
-
GLubytefly[]={
-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-
0x03,0x80,0x01,0xC0,0x06,0xC0,0x03,0x60,
-
0x04,0x60,0x06,0x20,0x04,0x30,0x0C,0x20,
-
0x04,0x18,0x18,0x20,0x04,0x0C,0x30,0x20,
-
0x04,0x06,0x60,0x20,0x44,0x03,0xC0,0x22,
-
0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
-
0x44,0x01,0x80,0x22,0x44,0x01,0x80,0x22,
-
0x44,0x01,0x80,0x22,0x44,0x01,0x80,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,0x10,0xc4,0x23,0x08,
-
0x10,0x63,0xC6,0x08,0x10,0x30,0x0c,0x08,
-
0x10,0x18,0x18,0x08,0x10,0x00,0x00,0x08
-
};
-
-
GLubytehalftone[]={
-
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,
-
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,
-
0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55
-
};
-
-
-
glClear(GL_COLOR_BUFFER_BIT);
-
-
glColor3f(1.0,1.0,1.0);
-
-
-
-
glRectf(25.0,25.0,125.0,125.0);
-
-
-
glEnable(GL_POLYGON_STIPPLE);
-
-
-
-
glPolygonStipple(fly);
-
-
glRectf(125.0,25.0,225.0,125.0);
-
-
-
glPolygonStipple(halftone);
-
-
glRectf(225.0,25.0,325.0,125.0);
-
-
-
glDisable(GL_POLYGON_STIPPLE);
-
-
glFlush();
-
-
}
-
-
-
-
-
-
-
-
voidreshape(intwidth,intheight){
-
-
glViewport(0,0,(GLsizei)width,(GLsizei)height);
-
-
glMatrixMode(GL_PROJECTION);
-
-
glLoadIdentity();
-
-
gluOrtho2D(0.0,(GLdouble)width,0.0,(GLdouble)height);
-
}
-
-
-
-
-
-
-
-
-
voidkeyboard(unsignedcharkey,intx,inty){
-
switch(key){
-
-
case27:
-
exit(0);
-
break;
-
}
-
}
-
-
-
intmain(intargc,constchar*argv[]){
-
-
-
glutInit(&argc,(char**)argv);
-
-
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
-
-
glutInitWindowSize(350,150);
-
-
glutInitWindowPosition(100,100);
-
-
glutCreateWindow("Lines");
-
-
-
init();
-
-
-
glutDisplayFunc(display);
-
glutReshapeFunc(reshape);
-
glutKeyboardFunc(keyboard);
-
-
-
glutMainLoop();
-
-
return0;
-
}

本文由CC原创总结,如需转载请注明出处:http://blog.csdn.NET/oktears/article/details/42264395 |