Week02 閻覃的上課筆記
繪製茶壺
函式原型
Declared In: glut.hextern void glutInit(int *argcp, char * *argv)
初始化GLUT
extern void glutInitDisplayMode(unsigned int mode)
初始化顯示模式
extern int glutCreateWindow(const char *title)
創建一個視窗,并設置標題
extern void glutMainLoop(void)
進入主循環
extern void glutSolidTeapot(GLdouble size)
繪製茶壺
extern void glutSwapBuffers(void)
交換雙緩衝區
extern void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
設定畫筆顏色,3f代表輸入紅綠藍三個float型變數。也可以使用3d、4s等。
源程式
1
2
3
static void display(void) {
4
glClearColor(1.0, 1.0, 1.0, 1.0);//設置顏色
5
glClear(GL_COLOR_BUFFER_BIT);//使用剛設置的顏色填充背景
6
glColor3f(1.0, 0.0, 0.0);//設置畫筆顏色
7
glutSolidTeapot(0.3);//畫茶壺
8
glutSwapBuffers();//交換雙緩存區
9
}
10
11
12
int main(int argc, char *argv[]) {
13
glutInit(&argc, argv);
14
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
15
glutCreateWindow("打得不錯");
16
glutDisplayFunc(display);
17
glutMainLoop();
18
}
繪製三角形
作業過程
訪問http://jsyeh.org/3dcg10/,下載老師的檔案
經過測試,Mac檔案無效。需要下載Source源程式手動編譯。

然後就可以按照程式中的代碼編寫自己的程式了。
函式原型
extern void glBegin(GLenum mode)extern void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
extern void glVertex2f(GLfloat x, GLfloat y)
extern void glEnd(void)
源程式
xxxxxxxxxx
26
1
2
3
static void display(void) {
4
glClearColor(1.0, 1.0, 1.0, 1.0);//設置顏色
5
glClear(GL_COLOR_BUFFER_BIT);//使用剛設置的顏色填充背景
6
7
glBegin(GL_TRIANGLES);
8
glColor3f(1.0, 0.0, 0.0);
9
glVertex2f(-1.0f, 1.0);
10
glColor3f(0.0, 1.0, 0.0);
11
glVertex2f(1.0, 1.0);
12
glColor3f(0.0, 0.0, 1.0);
13
glVertex2f(0, -1.0f);
14
glEnd();
15
16
glutSwapBuffers();//交換雙緩存區
17
}
18
19
20
int main(int argc, char *argv[]) {
21
glutInit(&argc, argv);
22
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
23
glutCreateWindow("打得不錯");
24
glutDisplayFunc(display);
25
glutMainLoop();
26
}

沒有留言:
張貼留言