2023年4月27日 星期四

Week11_toto

 Week11

step01-1

開啟codeblocks新增GLUT專案week11-1_keyborad


新增程式碼,會先製作出一個茶壺
#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)
{///step01-4
    if(key==27) exit(1234);///step01-1
}
int main(int argc,char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);///step01-1

    glutMainLoop();
}


step01-2

會結合keyboard會撥放音樂,新增GLUT專案week11-2_keyboard_PlaySound


新增程式碼,可以撥放出do re mi
#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)
{///step01-1 ///step01-2
    if(key=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do-re-mi\\do.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);
}///step01-2
int main(int argc,char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week11");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);///step01-1

    glutMainLoop();
}


step02-1
新增GLUT專案week11-3_PlaySound.cpp


設置咒語wimm


#include<windows.h>
#include<stdio.h>
int main()
{///Setting_Compiler,Linker咒語: 需要winmm
    ///絕對路徑 Absolue_Path
    ///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);
    ///相對路徑Relative Path
    printf("Hello World\n");
}

step02-2
從網路下載想要的音樂
新增GLUT專案week11-4_CMP3_MCI_Load_Play


移動檔案


程式碼不用刪除,從第137開始撰寫
新增五行程式碼
#include"CMP3_MCI.h"
///CMP3_MCI.h放在11-4_CMP_MCI_Load_Play程式同一個目錄
CMP3_MCI myMP3;

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

    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);


step03-1
開啟工作執行目錄

更改途徑為.
把所有東西放在同個目錄
#include"CMP3_MCI.h"
///CMP3_MCI.h放在11-4_CMP_MCI_Load_Play程式同一個目錄
CMP3_MCI myMP3;

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

    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);

step03-2
設定git 








沒有留言:

張貼留言