準備上課環境
0. freeglut
1. 安裝OPENCV
2. Setting_Compiler 有3個設定
檔名:week15-1_PlaySound
1.新增GLUT專案
2.全刪,只寫一行
'''cpp
#include <windows.h>
#include <GL/glut.h>
int main()
{
PlaySound("filename.wav",NULL,SND_SYNC);
}
'''
1.把CMP3_MCI.h 放在 week15-2_CMP3_MCI 目錄裡
'''cpp
#include "CMP3_MCI.h"
#include <stdio.h> ///為了scanf
CMP3_MCI myMP3;
int main()
{
myMP3.Load("filename.mp3");
myMP3.Play();
int a;
scanf("%d",&a);
}
'''
⚠如果沒有 scanf 程式會直接結束
檔名:week15-2_CMP3_MCI_sample
1.把CMP3_MCI.h 放在 week15-2_CMP3_MCI_sample 目錄裡
2.不要刪177行的範例。
插入
'''cpp
#include "CMP3_MCI.h"
'''
再插入
'''cpp
myMP3.Load("filename.mp3");
myMP3.Play();
'''
⚠音樂要放在目錄裡
檔名:week15-3_mouse_motion_glTranslatef_glRotatef
先貼上11行GLUT簡單版本
再加上程式碼
#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(angleX[0],0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
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_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week15-3");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言