一開始複習GLUT專案程式(圖一)(圖二)
這有個小改變
老師是寫glutSolidTeapot();
我寫的是glutWireTeapot();
差別是Solid是固態,Wire則是線條
圖一
glClearColor(); 一定要放在 glClear();的前面
glClearColor(); 可以改background的顏色
圖二
今天新的程式 (圖三)
1. glutMouseFunc(mouse); //要在main()裡
void mouse(int bottom, int state, int x, int y){
printf("glVertex2f(%f,%f);\n", (x-150)/150.0, (y-150)/150.0);
}
這為滑鼠的程式
在mouse的funtion裡,會有傳入四個參數
NO.1 滑鼠上的按鈕,左是0,中間滾輪是1,右是2
NO.2 滑鼠現在的狀態,0是按下,1是往上 (0和1會待配在一起)
NO.3 為X軸的座標值
NO.4 為Y軸的座標值
圖三
2.glutMotionFunc(motion);//要在main()裡
void display(){
...
...
glPushMatrix(); //備份矩陣
glTranslatef(tX,tY, 0); 移動
glutWireTeapot(0.3);
glPopMatrix();
...
...
}
void motion(int x, int y){
tX=(x-150)/150.0; tY=-(y-150)/150.0;
printf("%d %d\n", x, y);
glutPostRedisplay();
}
這為移動的程式
在motion的funtion裡,會有傳入兩個參數
NO.1 為X軸的座標值
NO.2 為Y軸的座標值
圖四
沒有留言:
張貼留言