文档详情

三维图形学实验报告.doc

发布:2017-08-13约字共35页下载文档
文本预览下载声明
实验一 (1)三角形: #include glut.h // glut.h includes gl.h and glu.h void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION);// 指定哪一个矩阵是当前矩阵 glLoadIdentity();//重置当前指定的矩阵为单位矩阵。 gluOrtho2D(-1.0, 1.0, -1.0, 1.0); // The para are: (left, right, bottom, top) 定义二维正交投影矩阵 glMatrixMode(GL_MODELVIEW); //指定哪一个矩阵是当前矩阵 } void display(void) { glClear(GL_COLOR_BUFFER_BIT); // Clear the frame buffer glColor3f(0.0, 1.0, 0.0); // Set current color to green glBegin(GL_POLYGON); // Draw the triangle glVertex2f(-0.7, -0.7); glVertex2f(0.7, -0.7); glVertex2f(0, 0.7); glEnd(); glFlush(); // Force to display the new drawings immediately } int main(int argc, char **argv) { glutInit(argc, argv); // Initialize GLUT function callings glutInitWindowSize(400, 400); glutInitWindowPosition(200, 100); // in numbers of pixels glutCreateWindow(Green Triangle); glutDisplayFunc(display); // is created or re-drew init(); // Invoke this function for initialization glutMainLoop(); // Enter the event processing loop return 0; // Indicate normal termination // (Required by ANSI C) }// 操作,定义事件回调函数 (2)点: void display(){ glClear(GL_COLOR_BUFFER_BIT); // Clear the frame buffer glColor3f(0.0, 1.0, 0.0); // Set current color to green glPointSize(10.); glBegin(GL_POINTS); glVertex2i(0.5,0.5); glEnd(); glFlush(); // Force to display the new drawings immediately } (3)线段: void display(){ glClear(GL_COLOR_BUFFER_BIT); // Clear the frame buffer glColor3f(0.0, 1.0, 0.0); // Set current color to green glLineWidth(3.0); glBegin(GL_LINES); glVertex3f(0., 0., 0.); glVertex3f(0., 1., 0.); glEnd(); glFlush(); // Force to display the new drawings immediately } (4)四边形: void display(){ glClear(GL_COLOR_BUFFER_BIT); // Clear the frame buffer glColor3f(1.0, 0.0, 0.0); // Set current color to green glRectf(0.6, 0.3, 0.2, 0.8); int vertex1[] = { 0.6, 0.3}; int vertex2[] = { 0.2, 0.8}; gl
显示全部
相似文档