1_使用範例檔,體驗點線面色彩的調動
檔案處理:將windows.zip解壓縮
將glut32.dll複製到windows資料夾中,data.zip也解壓縮複製到windows資料夾裡面
打開範例檔:點開一個名叫Shapes.exe的執行檔,會出現一個x,y座標圖,以及各個對應座標點與顏色的設定值
在座標軸的畫面中按滑鼠右鍵,選擇Specify colors@vertices 顯示顏色
在設定值的畫面中按滑鼠右鍵,選擇POLYGON[g],切換成三邊圖形
調整旁邊的設定值,可以產生不同的顏色和三邊形
如果按右鍵點選QUADS會產生四邊形的圖形
02_複習上週程式(畫茶壺)
下載freeglut(老師提供的版本):從FB 2017電腦圖學的社團中,可以找到檔案並且下載下來,待會會使用到
將freeglut存放位置路徑複製,以便建立一個新的GLUT專案
#include <GL/glut.h>
static void display(void)
{
glutSolidTeapot(0.3); //畫茶壺
glutSwapBuffers();
}
int main(int argc,chat *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes"); //視窗名稱glutDisplayFunc(display); //執行display(void)函式
glutMainLoop();
return EXIT_SUCCESS;
}
按下F9執行結果,會看到一個白色的茶壺
3_幫茶壺上顏色
利用前面的程式碼,將畫茶壺的程式碼前加上 glColor3f(1,0,0); 設定顏色
※glColor3f(r,g,b); //r=red g=green b=blue, 數值需介於0~1之間, 如有超過 n/255.0
#include <GL/glut.h>
static void display(void)
{
glColor3f(1,0,0); //將茶壺設定為紅色
glutSolidTeapot(0.3); //畫茶壺
glutSwapBuffers();
}
int main(int argc,chat *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes"); //視窗名稱glutDisplayFunc(display); //執行display(void)函式
glutMainLoop();
return EXIT_SUCCESS;
}
4_畫出三角形,設定顏色與頂點座標
GL_QUADS四邊形
GL_POLYGON多邊形
GL_POLYGON多邊形
重複三次設定個別的頂點顏色與座標
#include <GL/glut.h>
static void display(void)
{
glBegin(GL_POLYGON);
glColor3f(1,0,0); //將顏色設定為紅色
glVertex3f(0,0,0); //設定位置
glColor3f(0,1,0); //將顏色設定為綠色
glVertex3f(1,1,0); //設定位置
glColor3f(0,1,0); //將顏色設定為藍色
glVertex3f(-1,1,0); //設定位置
glEnd();
//glutSolidTeapot(0.3); //畫茶壺
glutSwapBuffers();
}
int main(int argc,chat *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes"); //視窗名稱glutDisplayFunc(display); //執行display(void)函式
glutMainLoop();
return EXIT_SUCCESS;
}


沒有留言:
張貼留言