#include<gl/glut.h> #include<windows.h> int n=0; float a0=200,b0=200,a1=400,b1=200,a2=400,b2=400,a3=200,b3=400; int winWidth=600,winHeight=500; void Initial(void) { glClearColor(1.0f,1.0f,1.0f,1.0f); } void ChangeSize(int w,int h) { winWidth=600,winHeight=550; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,winWidth,0.0,winHeight); } void Display() { glColor3f(0.0f,0.0f,0.0f); GLubyte fly[]= { 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff,0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, 0xff,0xff,0x00,0x00,0xff,0xff,0x00,0x00, }; glEnable(GL_POLYGON_STIPPLE); glPolygonStipple(fly); glRectf(5,5,800,800); glutSwapBuffers(); } int main(int argc,char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,100); glutCreateWindow("用黑白相间的棋盘图案填充多边形"); glutDisplayFunc(Display); glutReshapeFunc(ChangeSize); Initial(); glutMainLoop(); return 0; }
参考了别人的代码,刚接触这个东西,感觉函数名真多。。。尤其是vc++6.0没有智能感知,写的真累。