3、 } }}voidmyInit(void){ glClearColor(0.0,0.0,0.0,0.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); makeImage(); glPixelStorei(GL_UNPACK_ALIGNMENT,1); /*指定二维纹理映射*/ glTexImage2D(GL_TEXTURE_2D,0,3,imageWidth,imageHeight,0,GL_RGB,GL_UNSIGNED_BYTE,&image[0][0][0])
4、; /*设置纹理参数*/ glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
5、/*设置纹理环境参数*/ glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL); glEnable(GL_TEXTURE_2D); glShadeModel(GL_FLAT);}voidmyDisplay(void){ glClear(GL_COLOR_BUFFER_BIT
6、GL_DEPTH_BUFFER_BIT); /*将纹理映射到四边形上*/ glBegin(GL_QUADS); /*纹理的坐标和四边形顶点的对应*/ glTexCoord2f(0.0,0.0
7、);glVertex3f(-1.0,1.0,0.0); glTexCoord2f(0.0,1.0);glVertex3f(-1.0,-1.0,0.0); glTexCoord2f(1.0,1.0);glVertex3f(1.0,-1.0,0.0); glTexCoord2f(1.0,0.0);glVertex3f(1.0,1.0,0.0); glEnd(); glFlush();}voidmyReshape(intw,inth){ glViewport(0,0,(GLsizei)w,(GLsizei)h); glMa
8、trixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80.0,1.0-(GLfloat)w/(GLfloat)h,1.0,30.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}intmain(intargc,char**argv){ /*初始化*/ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE
9、GLUT_RGB); glutInitWindo
10、wSize(300,300); glutInitWindowPosition(200,200); /*创建窗口*/ glutCreateWindow("Texture"); /*绘制与显示*/ myInit(); glutReshapeFunc(myReshape); glutDisplayFunc(myDisplay); glutMainLo