(4) 回家作業: 畫圖
程式碼
#include <GL/glut.h> ///使用 GL/glut的外掛
void display()
{
///以下為綠色區塊部分
glBegin(GL_POLYGON);
glColor3f(0, 1, 0.2);
glVertex2f((345-300)/300.0, -(85-300)/300.0);
glVertex2f((122-300)/300.0, -(200-300)/300.0);
glVertex2f((49-300)/300.0, -(162-300)/300.0);
glVertex2f((271-300)/300.0, -(46-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0, 1, 0.2);
glVertex2f((345-300)/300.0, -(85-300)/300.0);
glVertex2f((415-300)/300.0, -(122-300)/300.0);
glVertex2f((345-300)/300.0, -(161-300)/300.0);
glVertex2f((271-300)/300.0, -(122-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0, 1, 0.6);
glVertex2f((271-300)/300.0, -(122-300)/300.0);
glVertex2f((345-300)/300.0, -(161-300)/300.0);
glVertex2f((345-300)/300.0, -(245-300)/300.0);
glVertex2f((271-300)/300.0, -(207-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0, 1, 0.4);
glVertex2f((271-300)/300.0, -(122-300)/300.0);
glVertex2f((271-300)/300.0, -(207-300)/300.0);
glVertex2f((123-300)/300.0, -(283-300)/300.0);
glVertex2f((123-300)/300.0, -(199-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0, 1, 0.6);
glVertex2f((123-300)/300.0, -(283-300)/300.0);
glVertex2f((49-300)/300.0, -(242-300)/300.0);
glVertex2f((49-300)/300.0, -(162-300)/300.0);
glVertex2f((123-300)/300.0, -(199-300)/300.0);
glEnd();
///以上為綠色區塊部分
///以下為橘色區塊部分
glBegin(GL_POLYGON);
glColor3f(1, 0.2, 0);
glVertex2f((345-300)/300.0, -(161-300)/300.0);
glVertex2f((415-300)/300.0, -(122-300)/300.0);
glVertex2f((492-300)/300.0, -(162-300)/300.0);
glVertex2f((420-300)/300.0, -(199-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0.6, 0);
glVertex2f((345-300)/300.0, -(161-300)/300.0);
glVertex2f((420-300)/300.0, -(199-300)/300.0);
glVertex2f((420-300)/300.0, -(367-300)/300.0);
glVertex2f((345-300)/300.0, -(330-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0.4, 0);
glVertex2f((420-300)/300.0, -(199-300)/300.0);
glVertex2f((492-300)/300.0, -(162-300)/300.0);
glVertex2f((492-300)/300.0, -(408-300)/300.0);
glVertex2f((420-300)/300.0, -(447-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0.2, 0);
glVertex2f((345-300)/300.0, -(329-300)/300.0);
glVertex2f((420-300)/300.0, -(367-300)/300.0);
glVertex2f((345-300)/300.0, -(408-300)/300.0);
glVertex2f((271-300)/300.0, -(367-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0.4, 0);
glVertex2f((345-300)/300.0, -(408-300)/300.0);
glVertex2f((420-300)/300.0, -(367-300)/300.0);
glVertex2f((420-300)/300.0, -(447-300)/300.0);
glVertex2f((345-300)/300.0, -(487-300)/300.0);
glEnd();
///以上為橘色區塊部分
///以下為紅色區塊部分
glBegin(GL_POLYGON);
glColor3f(1, 0, 0.6);
glVertex2f((345-300)/300.0, -(408-300)/300.0);
glVertex2f((271-300)/300.0, -(447-300)/300.0);
glVertex2f((123-300)/300.0, -(367-300)/300.0);
glVertex2f((203-300)/300.0, -(329-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0, 0);
glVertex2f((123-300)/300.0, -(283-300)/300.0);
glVertex2f((203-300)/300.0, -(242-300)/300.0);
glVertex2f((203-300)/300.0, -(329-300)/300.0);
glVertex2f((123-300)/300.0, -(367-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0, 0);
glVertex2f((271-300)/300.0, -(447-300)/300.0);
glVertex2f((345-300)/300.0, -(408-300)/300.0);
glVertex2f((345-300)/300.0, -(487-300)/300.0);
glVertex2f((271-300)/300.0, -(527-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0, 0.4);
glVertex2f((49-300)/300.0, -(242-300)/300.0);
glVertex2f((123-300)/300.0, -(283-300)/300.0);
glVertex2f((123-300)/300.0, -(447-300)/300.0);
glVertex2f((49-300)/300.0, -(408-300)/300.0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1, 0, 0.4);
glVertex2f((123-300)/300.0, -(447-300)/300.0);
glVertex2f((123-300)/300.0, -(367-300)/300.0);
glVertex2f((271-300)/300.0, -(447-300)/300.0);
glVertex2f((271-300)/300.0, -(527-300)/300.0);
glEnd();
///以上為紅色區塊部分
glutSwapBuffers();///最後buffer做交換秀出
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);///初始啟動GLUT
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///初始啟動GLUT的顯示模式,兩倍的,有3D的深度
glutCreateWindow("06160955_Week03");///創建視窗
glutDisplayFunc(display);///Display的函式是...display
glutMainLoop();///主要的迴圈
}
沒有留言:
張貼留言