學期內容回顧
1.Week01:下載freeglut資料夾&怎麼開起一個glut的檔案
先下載freeglut
複製一個freeglut32
2.Week02:學會製作一個點線面,色彩茶壺
(1) 所教程式碼: #include <stdio.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main (int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow("Week02 Hello World Triangle");
glutDisplayFunc(display);
glutMainLoop();
}
更改茶壺的顏色要使用 glColor3f() 函式
(2) 利用glClearColor 改背景顏色
3.Week03:使用移動,轉動,縮放,矩陣的程式碼
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();//備份矩陣
glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
glRotatef(angle, 0,0,1);///Now: 茶壺要對著 (0,0,1)做旋轉angle度
glutSolidTeapot(0.3);
glPopMatrix();//還原矩陣
glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
}

glPushMatrix();//備份矩陣
glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
glRotatef(angle, 0,0,1);///Now: 茶壺要對著 (0,0,1)做旋轉angle度
glutSolidTeapot(0.3);
glPopMatrix();//還原矩陣
glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
}

4.Week04: mouse加入,motion加入
void motion(int x, int y) //mouse motion 事件
{
if(nowRotate==1)angle += (x-oldX);///Now: 滑鼠的座標,就是轉的角度 Now2: 不好的移動 Now3: 新的動法, 加上新的增加量
else{
teapotX += (x-oldX)/150.0; /// 依照motion時的x來改teapot的座標 Now2: 不好的旋轉 Now3: 新的動法, 加上新的增加量
teapotY += (oldY-y)/150.0;/// 依照motion時的y來改teapot的座標 Now2: 不好的旋轉 Now3: 新的動法, 加上新的增加量
}

5.Week05:階層轉動
口訣,開始畫一個車子>放大縮小(一個車子)>旋轉(一個放大縮小的車子)>移動(整個)
glPushMatrix();
///glTranslated(-2.4,1.2,-6);///glRotated(60,1,0,0);
///glRotated(a,0,0,1);
glTranslated(0,0,-6);
glutSolidSphere(1,slices,stacks);
glPopMatrix();
6.Week06:T-R-T轉動
glPushMatrix();
glTranslatef();掛上去
glRoatate();小心旋轉可能為負
glTranslatef();
glPopMatrix();
7.Week07:貼圖
#include <opencv/highgui.h>///呼叫外掛 opencv的high
IplImage * img=NULL;///宣告指標 * 變數
img = cvLoadImage("image.jpg");///opencv讀入圖檔
cvShowImage("week10", img);///要秀出圖檔
IplImage * img=NULL;///宣告指標 * 變數
img = cvLoadImage("image.jpg");///opencv讀入圖檔
cvShowImage("week10", img);///要秀出圖檔
8.Week10:打光
1. 先到這個網站http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載 data.zip win.zip glut32.dll

2. 把這兩個檔案glut32.dll和data放到windows資料夾裡
然後開啟 Light Material.exe 執行

3.按右鍵可以改模型

4.左下方按右鍵可以改顏色

下載 data.zip win.zip glut32.dll

2. 把這兩個檔案glut32.dll和data放到windows資料夾裡
然後開啟 Light Material.exe 執行

3.按右鍵可以改模型

4.左下方按右鍵可以改顏色

9.Week11: 小考&聲音&音樂
laySound("shot.wav",NULL, SND_ASYNC);///呼叫播放聲音的函式
#include <mmsystem.h>///引用外掛 多媒體系統
void mouse(int button, int state, int x, int y)
if(state==GLUT_DOWN)PlaySound("Do.Wav").NULL, SND_ASYNC);///每案一次mouse,就發一聲
glutMouseFunc(mouse);///mouse事件laySound("shot.wav",NULL, SND_ASYNC);///呼叫播放聲音的函式
#include <mmsystem.h>///引用外掛 多媒體系統
void mouse(int button, int state, int x, int y)
if(state==GLUT_DOWN)PlaySound("Do.Wav").NULL, SND_ASYNC);///每案一次mouse,就發一聲
glutMouseFunc(mouse);///mouse事件

把音樂檔案丟到freeglut裡
就可以播放音樂了

11.Week12:使用計時器
#include "CMP3_MCT.h"///雙引號,在同一個目錄裡
CMP3_MCI myMP3;///計時器函式
PlaySound("Shot.wav",NULL, SND_ASYNC);}
myMP3.Load("123.mp3");///讀入檔案
myMP3.Play();///播放,MP3可當背景音樂
glutTimerFunc(4000, timer, 0);///使用計時器函式










沒有留言:
張貼留言