计算机图形学实验二

// 图形学实验一.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include"gl/glut.h" static GLsizei iMode =0; void Initial(void) { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 200.0, 0.0, 150.0); } void Display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0f, 0.0f, 0.0f); if (iMode == 1) { glRectf(50.0f, 100.0f, 150.0f, 50.0f); } else if(iMode==2){ 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(50.0f, 100.0f, 150.0f, 50.0f); } glutSwapBuffers();//交换命令缓冲区 } void ProcessMenu(int value) { iMode = value; glutPostRedisplay(); } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);//使用双缓存及RGB模型 glutInitWindowSize(400, 300);//指定窗口的大小 glutInitWindowPosition(100, 100);//指定窗口在屏幕上的位置 glutCreateWindow("用棋盘图形填充矩形"); glutCreateMenu(ProcessMenu); glutAddMenuEntry("不填充矩形 ", 1); glutAddMenuEntry("填充矩形", 2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutDisplayFunc(Display); Initial(); glutMainLoop();//启动主GLUT时间处理循环 return 0; }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步