與上週課堂一開始一樣開啟並下載檔案>練習Shapes

*將籃框下載後開啟我的電腦>下載
將windows解壓縮到windows\(E)>拉到桌面
再將壓所檔裡的data&glut32拉到解壓縮後的windows
按Alt+T>資料夾選項>檢視>關閉隱藏附檔名 完成!

課堂作業2:
開啟GLUT新增Project>修改程式碼>做出有顏色的多邊形

*反黑部分要記得按"Tab"
*逗點","後面+空格(比較好看)
程式碼如下:
#include <GL/glut.h>
void display()
{
///glutSolidTeapot(0.3);
glBegin(GL_POLYGON);
glColor3f(1, 1, 0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMainLoop();
}
課堂作業3:
寫程式碼做出多種顏色多邊形

程式碼如下:
#include <GL/glut.h>
void display()
{
glClearColor(0.5, 0.5, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-1.0, 0.0, 0.0);
glColor3f(0, 1, 0); glVertex3f( 1.0,-1.0, 0.0);
glColor3f(0, 0, 1); glVertex3f( 1.0, 1.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMainLoop();
}
開啟小畫家>將google的圖片貼上後>修改大小
*記得".0"要加【口訣:整數除整數等於整數】
#include <GL/glut.h>
void display()
{
glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
//glColor3f(192/255.0, 215/255.0, 107/255.0);
glColor3ub(192, 215, 107);
glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMainLoop();
}

*glutSwapBuffers(); 只能放最後!

#include <GL/glut.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
printf(" glVertex3f((%d-150)/150.0, -(%d-150)/150.0, 0.0);\n", x, y);
}
void display()
{
glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
//glColor3f(192/255.0, 215/255.0, 107/255.0);
glColor3ub(192, 215, 107);
glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f((202-150)/150.0, -(22-150)/150.0, 0.0);
glVertex3f((268-150)/150.0, -(22-150)/150.0, 0.0);
glVertex3f((266-150)/150.0, -(90-150)/150.0, 0.0);
glVertex3f((217-150)/150.0, -(87-150)/150.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f((214-150)/150.0, -(221-150)/150.0, 0.0);
glVertex3f((274-150)/150.0, -(223-150)/150.0, 0.0);
glVertex3f((275-150)/150.0, -(271-150)/150.0, 0.0);
glVertex3f((226-150)/150.0, -(266-150)/150.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f((26-150)/150.0, -(224-150)/150.0, 0.0);
glVertex3f((86-150)/150.0, -(224-150)/150.0, 0.0);
glVertex3f((89-150)/150.0, -(267-150)/150.0, 0.0);
glVertex3f((28-150)/150.0, -(266-150)/150.0, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}

沒有留言:
張貼留言