## week15-1_PlaySound
要在小黑執行可以播放作業
#include <windows.h>
#include <GL/glut.h>
int main()
{
PlaySound("mykbeat.wav",NULL,SND_SYNC);
}
上網下載wav音樂檔案 放在freeglut的bin資料夾裡面
音樂播完就會結束,所以可以一次播好幾個wav檔案
也不用一定要放在bin資料夾裡
按專案按右鍵選最下面的 properties
因為wav檔案太大很難找到 所以貼一個檔案之後就可以讀入mp3檔案
開啟glut範例檔案 保留 177行 不要刪掉 中間插入四行
在main函式前面插入兩行
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
裡面插入
myMP3.Load("123.mp3");
myMP3.Play();
我們需要最下面的mainLoop 來卡住程式不要太快結束
## week15-3_mouse_motion_glTranslatef_glRotatef
要讓物體可以左右移動位置
先寫完11行程式 再去改
#include <GL/glut.h>
void display(){
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main()(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode((GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15-3");
glutDisplayFunc(display);
glutMainLoop();
}
改成這樣 確定有畫出模型就可以把背景顏色刪掉
#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);
glutKeyboardUpFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
glTranslatef(angleX[14]/150.0,-angleY[14]/150.0,0); 這行要除以150.0 讓移動位置不要那麼快
沒有留言:
張貼留言