(1)老師讓大家下載 data.zip, windows.zip, glut32.dll 這3個檔案
網址 → http://jsyeh.org/3dcg10

(2)解壓縮windows和data,然後把glut32丟進windows資料夾裡

(3)就可以開啟shape.exe

(4)可以開始試試各種功能



2. 用滑鼠移動茶壺

程式碼:
#include <stdio.h> ///printf()要用到
#include <GL/glut.h> ///整套GLUT外掛
float teapotX=0, teapotY=0; ///Now: 茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///Now: 備份矩陣
glTranslatef(teapotX, teapotY, 0); ///Now: 依照 茶壺的座標 移動
glutSolidTeapot(0.3);
glPopMatrix(); ///Now: 還原矩陣
glutSwapBuffers(); ///搭配GLUT_DOUBLE兩倍顯示
}
///冷笑話:把大象放到冰箱去的方法:(1)把冰箱門打開 (3)把冰箱門關上
void mouse(int button, int state, int x, int y)
{///button: 左、中、右鍵, state: 按下去/彈起來, x, y: mouse位置
///printf("%d %d %d %d\n", button, state, x, y);
} ///如果mouse往下, 才印程式
void motion(int x, int y) ///mouse motion事件
{///(2)把大象放到冰箱裡面去
teapotX=(x-150)/150.0; teapotY=(150-y)/150.0; ///Now: 依照motion時的x, y來改teapot的座標
glutPostRedisplay(); ///Now: 請3M Post便利貼, 貼出來說, 有空時, 記得要Redisplay()
}
int main(int argc, char**argv) ///完整的main()參數
{
glutInit(&argc, argv); ///初始的參數, 照著丟進去
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///2個顯示的參數
glutCreateWindow("Week03 Mouse"); ///本週的Window標題改一下
glutDisplayFunc(display); ///等一下樓上會有display()
glutMouseFunc(mouse); ///等一下樓上會有mouse()滑鼠的事件
glutMotionFunc(motion); ///Now: 等一下樓上會有mouse()滑鼠motion事件
glutMainLoop(); ///主要GLUT迴圈
}
沒有留言:
張貼留言