2023年4月27日 星期四

小凱week11

 主題:keyboard,音效

第一節課

今天先介紹keyboard,開啟一個新的GLUT專案(前幾週有步驟),建完後用ctrl+f搜尋key。

step01-1:透過鍵盤控制

結合鍵盤來寫一段程式,27鍵可以關掉。
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key==27) exit(1234);
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week 11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}

step01-2:音效

把step01-1的程式碼複製過來,加上幾行程式碼,再把音檔的位置複製到程式碼裡。

第二節課:試問能在Hello World放出音檔嗎?

step02-1:把第一節課學到的音檔來用

開一個空白檔另存成week11-3_PlaySound.cpp,開完在Settings>Compiler>Link加上winm
補充:目錄的斜線可以用兩個反斜線,或者是一個斜線!!
#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\do.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\re.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\week11\\do-re-mi\\mi.wav",NULL,SND_SYNC);
    printf("Hello World");
}
剛剛所介紹會音檔的方式都是用絕對路徑,那試用相對路徑,看看能不能讀到音檔。
接著奢給我們一個音檔,建一個新GLUT檔,加一些程式碼。
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
char filename[]="C:/Users/Administrator/Desktop/week11-4_CMP3_MCI_Load_Play/拌.mp3";
myMP3.Load(filename);
myMP3.Play();

第三節課

step03-1

1.把freeglut裡的freeglut.dll複製到week11-4裡。
2.解決歷史餘毒:先存檔後,在project>properties>Build target>Execution working dir改成.,之後在save everything。

step03-2

使用github指令把2023graphiccsb下載到桌面,把gitinore用notepad++開起來,再把doll註解掉,就可以把freeglut.doll放到github上。
把今天的檔案推到github上,結束!!

沒有留言:

張貼留言