(2)貼圖:貼圖座標 glTexCoord2f(tx,ty);
開啟Texture.exe測試貼圖
1.產生聲音
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void mouse (int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav",NULL,SND_ASYNC);
printf("shot!\n");
}
}
void keyboard(unsigned char key,int x,int y)
{
exit(0);
}
void display()
{
glClearColor(0.5, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("ªhello!");
glutFullScreen();///全螢幕
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
///return 0;
}
2.茶壺出現 移動
include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
void mouse (int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav",NULL,SND_ASYNC);
printf("shot!\n");
}
}
void keyboard(unsigned char key,int x,int y)
{
exit(0);
}
float potX=-1,potY=0;
void display()
{
potX+=0.01;
if(potX>1.1) potX=-1.1;
glClearColor(0.5, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(potX,potY,0);
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("ªhello!");
glutFullScreen();///全螢幕
glutDisplayFunc(display);
glutIdleFunc(display); ///
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
///return 0;
}
3.增加射擊聲音及擊中的聲音
#include <GL/glut.h>
#include <stdio.h>
#include <mmsystem.h>
#include <math.h>
float potX=-1,potY=0;
void mouse (int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav",NULL,SND_ASYNC);
printf("shot!\n");
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("menuclick.wav",NULL,SND_ASYNC);
printf("shot!\n");
} //偵測到茶壺射擊後發出的叫聲
}
}
void keyboard(unsigned char key,int x,int y)
{
exit(0);
}
void display()
{
potX+=0.01;
if(potX>1.1) potX=-1.1;
glClearColor(0.5, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(potX,potY,0);
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("ªhello!");
glutFullScreen();///全螢幕
glutDisplayFunc(display);
glutIdleFunc(display); ///
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
///return 0;
}
沒有留言:
張貼留言