2023年4月27日 星期四

島輝! week11

 

WEEK11

Step01-1

開啟CODEBLOCK


開專案







打專案名稱 選擇檔案存檔位置



解壓縮freeglut

開啟freeglut>lib>複製libfreeglut>貼上名稱改成libglut32
codeblock選擇freeglut完成>他跑出來就會生成三個神祕圖形



把程式刪掉
換上以下程式碼:
#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("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}





會出現茶壺然後按下ESC鍵可以把視窗關掉
*key==27 就是ESC




Step01-2



按按鍵播出聲音

修改一下程式碼:

#include <windows.h>
#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=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,SND_ASYNC);
    if(key=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\mi.wav",NULL,SND_ASYNC);
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();
}



按1、2、3會出現音效DO、RE、MI






Step02-1 WAV



把播放音效改成cpp播放

#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,ASND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,ASND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\mi.wav",NULL,ASND_SYNC);
    printf("Hello World\n");
    }



點Settings>Compiler



點Linker settings>分別Add>winmm






會慢慢地依序播放聲音 最後出現Hello World






#include <windows.h>
#include <stdio.h>
int main()
{
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,SND_SYNC);
    PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\mi.wav",NULL,SND_SYNC);
///絕對路徑
    PlaySound("do-re-mi/do.wav",NULL,SND_SYNC);///相對路徑

    printf("Hello World\n");
    }



Step02-2 MP3





重開一個GLUT專案檔

#include "CMP3_MCI.h"

CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    char filename[]="C:/Users/Administrator/Desktop/do-re-mi/音樂名稱.mp3";
    myMP3.Load(filename);
    myMP3.Play();


要把CMP3_MCI.h丟進去專檔裡面




這樣就可以播放mp3音樂






Step03-1 MP3相對路徑




Project>Properties



Build targets> Execution working dir:[.]  把裡面路徑改成.



#include "CMP3_MCI.h"

CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    char filename[]="C:/Users/Administrator/Desktop/do-re-mi/音樂名稱.mp3";
    myMP3.Load(filename.mp3);
    myMP3.Play();


要把音樂檔案放進去專案檔裡面

把freeglut >bin >freeglut.dll的檔案也放進去專案檔裡面













Step03-2


安裝git 開啟GIT bash

cd desktop 進入桌面
git clone 複製你的檔案



開啟2023graphicsb>.gitgnore

*用Notepad++開啟


把*.dll註解掉




cd 進入你的檔案
git add . 加入你的檔案
git status 確認你的檔案
git config --global user.email 你的Gmail
git config --global user.name 你的GitHubID
git commit -m "你的周次"
git push 上傳








結束


沒有留言:

張貼留言