1)下載NeHe Lesson32.zip
解壓縮,玩自製遊戲
http://nehe.gamedev.net/
Lesson32
2)window.zip範例
○Light Material(打光)
○Texture(貼圖)
期中考題
3)freeglut
New project GLUT專案
void mouse (int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
PlaySound("Shot.wav", NULL, SND_ASYNC);
printf("Show!\n");
}
並且將Lesson32內的Shot.wav音訊檔案放入bin資料夾
主程式內加這行:glutMouseFunc(mouse);
void keyboard(unsigned char key, int x, int y)
{
exit(0);
}
按任意鍵退出
5)
glutIdleFunc(display);//空閒時一直跑,不定速
float potX=-1, potY=0;//外部變數設定物件座標
void display()
{
potX+=0.01;//每次移動0.01
if(potX>1.1) potX=-1.1;//當超過螢幕右側邊緣時則回到左邊邊緣
glClearColor(1, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//備份
glTranslatef(potX, potY, 0);//起始點為外部變數設定的兩點
glutSolidTeapot(0.07);//物件為實心茶壺
glPopMatrix();//還原
glFlush();//沖出
}
6)
計算是否正確點擊物件
float mouseX = 2*x/1280.0-1, mouseY = 2*y/1024.0-1;
if(fabs(mouseX-potX)<0.1 && fabs(mouseY-potY)<0.1)//條件
PlaySound("BULLET.wav", NULL, SND_ASYNC);//擊中時發出的聲音
printf("you got it!\n");//小黑框顯示
glutIdleFunc(display);//空閒時一直跑,不定速
float potX=-1, potY=0;//外部變數設定物件座標
void display()
{
potX+=0.01;//每次移動0.01
if(potX>1.1) potX=-1.1;//當超過螢幕右側邊緣時則回到左邊邊緣
glClearColor(1, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//備份
glTranslatef(potX, potY, 0);//起始點為外部變數設定的兩點
glutSolidTeapot(0.07);//物件為實心茶壺
glPopMatrix();//還原
glFlush();//沖出
}
計算是否正確點擊物件
float mouseX = 2*x/1280.0-1, mouseY = 2*y/1024.0-1;
if(fabs(mouseX-potX)<0.1 && fabs(mouseY-potY)<0.1)//條件
PlaySound("BULLET.wav", NULL, SND_ASYNC);//擊中時發出的聲音
printf("you got it!\n");//小黑框顯示
沒有留言:
張貼留言