1.
step1: 下載 freeglut-MinGW-3.0.0-1.mp.zip
step2: 進到資料夾,把檔案 freeglut 拉到桌面
step3: 點進 freeglut 👉 lib 資料夾
step4: 複製 libfreeglut.a 並且改名為libglut32.a
step5: 安裝 OpenCV 要勾 Add PATH (第二個),裝在預設目錄
👉 Setting-Compiler 裡,要把 OpenCV 的三個設定設好
👇
(1) 重開 CodeBlocks
👇 原本的檔案在 View 👉 Start Page
(2) 在 Search directories 加入2個目錄
1-1 Compiler 👉 C:\OpenCV2.1\include
1-2 Linker 👉 C:\OpenCV2.1\lib
(3) 在 Linker setting 裡,加入 👉 cv210
👉 cxcore210
👉 highgui210
step6: 開新專案(File-New-Project),專案名稱為 "week15-1_PlaySound"
step7: 全刪,只寫一行
#include <windows.h>
#include <GL/glut.h>
int main()
{
PlaySound("filename.wav", NULL, SND_SYNC);
///等待播玩音樂,才結束
}
2.
step1: 開新專案(File-New-Project),專案名稱為 "week15-2_CMP3_MCI"
step2: 將老師給的 CMP3_MCI.h,放在 week15-2_CMP3_MCI 目錄裡
step3: 程式碼
#include "CMP3_MCI.h" //記得要用雙引號,不能用角括號
#include <stdio.h> ///為了 scanf
CMP3_MCI myMP3; ///宣告一個變數,名字叫做 myMP3
int main()
{
myMP3.Load(".mp3");
myMP3.Play();
int a; ///幫忙卡住,程式不要快速結束
scanf("%d", &a);
}
step4: 重開新專案,專案名稱為 "week15-2_CMP3_MCI_sample"
step5: 將老師給的 CMP3_MCI.h,放在 week15-2_CMP3_MCI_sample 目錄裡
step6: 不要刪177行的範例,我們想共存,請插入
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
再插入
myMP3.Load("檔名.mp3");
myMP3.Play();
3.
step1: 開新專案(File-New-Project),專案名稱為
"week15-3_mouse_motion_glTranslatef_glRotatef"
step2: 貼上11行 GLUT 簡單版本(今天不用 glm.cpp 不用 OpenCV)
step3: 程式碼
#include <GL/glut.h>
float angleX[15] = {}, angleY[15] = {}; ///關節要夠用
void display()
{
//glClearColor(1,1,0,1); ///黃色背景
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(angleX[14]/150.0, angleY[14]/150.0, 0); ///拿來當成移動的變數
glRotatef(angleX[0], 1, 0, 0);
glRotatef(angleY[0], 0, 1, 0);
glPushMatrix();
glScalef(0.2, 0.2, 0.2);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int angleID = 0, oldX = 0, oldY = 0;
void mouse(int button, int state, int x, int y)
{
oldX = x;
oldY = y;
}
void motion(int x, int y)
{
angleX[angleID] += x-oldX;
angleY[angleID] += y-oldY;
oldX = x;
oldY = y;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='x') angleID = 14;
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutMainLoop();
}
註: 按 X 可移動
加入縮放
沒有留言:
張貼留言