1.電腦圖學之父Ivan Sutherland
2.jsyeh.org/3dcg10下載data.zip,windows
3.開啟codeblocks
貼上之前的程式碼
並且稍作修改,加上keyboard函式
按下鍵盤任一按鍵後,會顯示你按下的鍵和目前滑鼠所在的位置座標
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);///黃色的
glutSolidTeapot(0.3);///茶壺
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
printf("你按下了 %c 在 %d %d 座標\n",key,x,y);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
然後我們接續剛剛的程式碼
改成keyboard+mouse+motion
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);///黃色的
glutSolidTeapot(0.3);///茶壺
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
}
void mouse(int button,int state,int x,int y)
{
}
void motion(int x,int y)
{
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言