1)作業互評品味
2)Keyboard、Mouse、UI
3)音效、音樂
4)期中考題目、答案
5)模擬考
todo:freegult windows下載 解壓縮 改libgult32.a
todo:glutKeyboardFumc(keyboard);
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
if(key=='a')printf("aaaaa\n");
if(key=='b')printf("bbbbb\n");
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
接下來要加入音效,到這網址http://billor.chsh.chc.edu.tw/sound/boom.htm下載音效
選好音效另存連結到freeglut/bin資料夾
加入音效後的茶壺
#include <GL/glut.h>
#include <stdio.h>
#include<mmsystem.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
if(key=='a'){
PlaySound("wave.way",NULL,SND_ASYNC);
printf("aaaaa\n");
}
if(key=='b')printf("bbbbb\n");
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
加入鋼琴Do Re Me
#include <GL/glut.h>
#include <stdio.h>
#include<mmsystem.h>
void display()
{
glutSolidTeapot(0.3);
glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
if(key=='a'){
PlaySound("wave.way",NULL,SND_ASYNC);
printf("aaaaa\n");
}
if(key=='1')PlatSound("Do.way",NULL,SND_ASYNC);
if(key=='2')PlatSound("Re.way",NULL,SND_ASYNC);
if(key=='3')PlatSound("Me.way",NULL,SND_ASYNC);
if(key=='4')PlatSound("Fa.way",NULL,SND_ASYNC);
if(key=='5')PlatSound("Sol.way",NULL,SND_ASYNC);
if(key=='6')PlatSound("La.way",NULL,SND_ASYNC);
if(key=='7')PlatSound("Si.way",NULL,SND_ASYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
---------------------------------------------------------------------------------------------
滑鼠控制
#include <GL/glut.h>
#include <stdio.h>
#include<mmsystem.h>
float teaY=0,rotX=0,rotY=0,oldX=0,oldY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,teaY,0);
glRotatef(rotX,1,0,0);
glRotatef(rotY,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glFlush();
}
void keyboard(unsigned char key, int x,int y)
{
if(key=='a'){
PlaySound("wave.wav",NULL,SND_ASYNC);
printf("aaaaa\n");
}
}
void special(int key,int x,int y)//上下鍵盤移動
{
if(key==GLUT_KEY_DOWN)
{
teaY-=0.1;printf("down\n");
}else if(key==GLUT_KEY_UP){
teaY+=0.1;printf("up\n");
}
glutPostRedisplay();
}
void mouse(int button,int state,int x,int y)
{
oldX=x; oldY=y;
if(GLUT_LEFT_BUTTON==button&&GLUT_DOWN==state)printf("now left down\n");
if(GLUT_RIGHT_BUTTON==button&&GLUT_DOWN==state)printf("now right down\n");
}
void motion(int x,int y)
{
rotX+=y-oldY;
rotY+=x-oldX;
oldX=x; oldY=y;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("hello");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言