2023年4月27日 星期四

week11 余

Week11 

今天上課的第一個程式先開glut專案

檔名week11-1_keyboard

程式碼全刪加入以下程式碼

#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按鍵茶壺就會不見並回傳數字


今天的第二個程式
再開一個Glut專案 檔名為week11-2_keyboard_PlaySound
程式碼如下
#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\\so.wav",NULL,SND_ASYNC);
    if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\re.wav",NULL,SND_ASYNC);
    if(key=='3') 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 的聲音了~~~
今天的第三個程式
檔名為week11-3_PlaySound.cpp
程式碼如下
#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);
    printf("Hello World\n");
}

會依序撥放音檔

今天的第四個程式 檔名week11-4_CMP3_MCI_load_Play
將老師傳的檔案CMP3_MCI.h加入week14-4資料夾
加入下列幾行程式
#include "CMP3_MCI.h"
CMP3_MCI myMP3;

char filename[] = "C:/Users/Administrator/Desktop/do-re-mi/suzume.mp3";
    myMP3.Load(filename);
    myMP3.Play();



就會開始撥放音樂了~

今天第三節課
照著圖片去修改
最後要記得save everything
在week11-4資料夾中加入freeglut.dll
和老師傳的音檔

並去codeblock修改

最後再修改其中一行程式碼

執行後就會直接撥放音樂了
不用再打一長串所在目錄了~~~
最後在上傳到GITHUB
cd desktop
git clone https://github.com/dannyyu0521/2023graphicsb
cd 2023graphicsb
將檔案放入資料夾
git status
git add .
git status
git config --global user.email dannyyyu0521@gmail.com
git config --global user.name dannyyu0521
git commit -m "add week11"
git push

沒有留言:

張貼留言