这段时间笔者几篇文章介绍了改窗口设置的文章. 关联文章的地址
#include <gl/glut.h> static GLsizei iMode = 1; static GLfloat sx = 1.0; static GLfloat sy = 1.0; static GLfloat tx = 0.0f; static GLfloat ty = 0.0f; void Initial(void) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //设置窗口背景颜色为白色 gluOrtho2D(-30.0,30.0,-20.0,20.0);//居中显示 } void ChangeSize(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); //设置投影参数 glLoadIdentity(); gluOrtho2D(-30.0,30.0,-20.0,20.0);//居中显示 } void Display(void) { glClear(GL_COLOR_BUFFER_BIT); //用以后背景色填充窗口 glMatrixMode(GL_PROJECTION); //设置投影参数 glLoadIdentity(); glTranslatef(tx, 0.0f, 0.0f); glTranslatef(0.0f, ty, 0.0f); glScalef(sx,sy,0.0f);//左键每一次点击扩展0.1 glColor3f(1.0f, .0f, 0.0f); //设置以后的绘图颜色为红色 switch(iMode) { case 1: glColor3f(.0f, 0.0f, 0.0f); //黑 break; case 2: glColor3f(1.0f, .0f, .0f); //红 break; case 3: glColor3f(0.0f, .0f, 1.0f); //蓝 break; case 4: glColor3f(.0f, 1.0f, 0.0f); //绿 break; case 5: glColor3f(1.0f, 1.0f, 1.0f); //白 break; case 6: glDisable(GL_LINE_STIPPLE); break; case 7: glEnable(GL_LINE_STIPPLE); glLineStipple(1,255); break; default : break; } //多边形的绘制 glBegin(GL_LINE_LOOP); glVertex2f(-10,-10); glVertex2f(10,-10); glVertex2f(20,0); glVertex2f(0,10); glVertex2f(-20,0); glEnd(); glFlush(); //处置全部的OpenGL程序 } void ProcessMenu(int value) { iMode = value; glutPostRedisplay(); } //键盘交互调用函数 void Key(unsigned char key,int x,int y) { switch(key) { case 'q': exit(0); break; case 'Q': exit(0); break; case 'S': sx+=0.1; sy+=0.1; glutPostRedisplay(); break; case 'D': sx-=0.1; sy-=0.1; glutPostRedisplay(); break; default: break; } } //如果是鼠标键控制旋转,可以参考p93 void SpecialKeys(int key,int x,int y) { if(key == GLUT_KEY_UP) ty += 0.1f; if(key == GLUT_KEY_DOWN) ty -= 0.1f; if(key == GLUT_KEY_LEFT) tx -= 0.1f; if(key == GLUT_KEY_RIGHT) tx += 0.1f; glutPostRedisplay(); } //鼠标交互调用函数,左键缩小,右键扩展 void MousePlot(GLint button,GLint action,GLint xMouse,GLint yMouse) { if(button == GLUT_LEFT_BUTTON && action == GLUT_DOWN) { sx+=0.1; sy+=0.1; } if(button ==GLUT_RIGHT_BUTTON && action == GLUT_DOWN) { sx-=0.1; sy-=0.1; } glutPostRedisplay(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //初始化窗口的显示模式 glutInitWindowSize(800,800); //设置窗口的尺寸 glutInitWindowPosition(600,120); //设置窗口的位置 glutCreateWindow("矩形"); //创建一个名为矩形的窗口 //创建菜单 int color= glutCreateMenu(ProcessMenu); glutAddMenuEntry("黑色",1); glutAddMenuEntry("红色",2); glutAddMenuEntry("蓝色",3); glutAddMenuEntry("绿色",4); glutAddMenuEntry("白色",5); int lineStrpple = glutCreateMenu(ProcessMenu); glutAddMenuEntry("直线",6); glutAddMenuEntry("虚线",7); int nMainMenu = glutCreateMenu(ProcessMenu); glutAddSubMenu("颜色",color); glutAddSubMenu("线型",lineStrpple); glutAttachMenu(GLUT_MIDDLE_BUTTON);//与鼠标中键绑定 glutKeyboardFunc(Key); //普通键输入注册函数 glutSpecialFunc(SpecialKeys); glutMouseFunc(MousePlot); //注册鼠标响应函数 //glutMotionFunc(MouseMove);//鼠标按下并挪动时的响应函数 //glutReshapeFunc(ChangeSize); glutDisplayFunc(Display); //设置以后窗口的显示回调函数 Initial(); //完成窗口初始化 glutMainLoop(); //启动主GLUT事件处置循环 return 0; }
文章结束给大家分享下程序员的一些笑话语录: PC软件体积大,是因为一个PC软件功能往往较多,能够满足你一个方面的需求,而一个iphone软件往往没几行代码,干一件很小的事情,自然需要的软件就多。就像吃西瓜和吃瓜子的来比数目,单位不同啊。
--------------------------------- 原创文章 By
窗口和设置
---------------------------------