week15
架環境
'''cpp
#include <windows.h>
#include <GL/glut.h>
int main()
{
PlaySound("filename.wav", NULL, SND_SYNC);
//等待播完音樂,才結束
}
'''
使用wav.,NO mp3!!
音檔放在C:\Users\Administrator\Desktop\freeglut\bin
改工作目錄
複製音檔和freeglut.dll到專案資料夾
改工作目錄:右鍵專案properties>Build targets>Excecution working dir(改成.)
#week15-2_CMP3_MCI
1.File-New-Project, GLUT專案, 15-2_CMP3_MCI
2.老師準備了 CMP3_MCI.h 傳給你了, 請放在桌面上的week15-2_CMP3_MCI目錄裡
'''
#include <stdio.h> //為了scanf()
#include "CMP3_MCI.h" //記得要用雙引號,不能用角括號
CMP3_MCI myMP3; //宣告一個變數,名字叫 myMP3
int main()
{
myMP3.Load("filename.mp3");
myMP3.Play();
int a;//幫忙卡住, 程式不要快速結束
scanf("%d",&a);
}
'''
##week15-2_CMP3_MCI_sample
1.File-New-Project,GLUT專案,week15-2_CMP3_MCI_sample
2.把CMP3_MCI.h 放在同一個目錄 week15-2_CMP3_MCI_sample
3.不要刪177行的範例
'''cpp
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
'''
再插入
'''cpp
myMP3.Load("檔名.mp3");
myMP3.Play();
'''
##week15-3_mouse_motion_glTranslatef_glRotatef
1.File-New-Project, GLUT專案
2.貼上11行GLUT簡單版本
'''cpp
#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);
glutSolidTeapot(0.3);
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_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15-3");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);///等一下會有程式放這裡
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
'''
.png)
沒有留言:
張貼留言