week05
1.做出按下鍵盤按鍵印出滑鼠所在的座標
#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 keyboard");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
2.點擊移動
void motion(int mouseX,int mouseY)
{
if( mouseX-oldX >0) scale*= 1.01;
if( mouseX-oldX <0) scale*= 0.99;
///x+=(mouseX-oldX); y+=(mouseY-oldY);
oldX =mouseX; oldY= mouseY;
display();
}



沒有留言:
張貼留言