2018年5月18日 星期五

Week12 游伃瑄

(1) 在 Codeblocks 開啟 GLUT 程式


到moodle下載freeglut-MinGW-3.0.0-1.mp.zip > 解壓縮 > freeglut > lib > 
複製libfreeglut.a > 貼上並重新命名為libglut32.a > 開啟Codeblocks > File > 
New > Project > GLUT

(2) 在main函式的上方加入 #include <mmsystem.h>
下方加入 PlaySound("Do.wav",NULL,SND_ASYNC);



(3) 將 Do.wav 音檔放入 freeglut -> bin 資料夾內



--------------------------------------------------------------------------------

(1) 讓程式可以播放MP3檔

main函式上方加入 
#include "CMP3_MCI.h"
CMP3_MCI       myMP3;

main函式內加入
myMP3.Load("123.wav");
myMP3.Play;

--------------------------------------------------------------------------------

(1) 播放音檔時結合計時器

#include <windows.h> //因為mmsystem.h需要windows.h
#include <mmsystem.h> // 多媒體系統,用來PlaySound()
void timer(int t)
{
    glutTimerFunc(1000,timer,t+1); //須等待的秒數,呼叫timer,參數
    PlaySound("Do.wav", NULL, SND_ASYNC);
}

計時器函式 glutTimerFunc(5000, timer,0); 



(2) 在小黑窗可印出次數

printf("Now t is : %d\n",t);





--------------------------------------------------------------------------------

(1)計時器結合內插法



#include <stdio.h>
#include <GL/glut.h>
float angle=0,oldAngle=0,newAngle=90; //角度,新角度,舊角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1); // 照著角度旋轉
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void timer(int t)
{
    glutTimerFunc(1000,timer,t+1);
    float alpha=(t)/30.0; //內差的alpha值
    angle=newAngle*alpha+oldAngle*(1-alpha); //角度內插
    glutPostRedisplay(); //照著內插後的值重畫
}
int main(int argc, char *argv[])
{

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

    glutCreateWindow("GLUT Shapes");

    glutTimerFunc(0, timer,0); //計時器函式
    glutDisplayFunc(display);
    glutMainLoop();
}



沒有留言:

張貼留言