week03
![]() |
| 開起茶壺 |
![]() |
| 點出座標 |
![]() |
| 拖曳滑鼠變顏色 |
#include <stdio.h>
#include <GL/glut.h>
//#include <GLUT/glut.h>//Apple
void mouse(int button, int state,int x,int y)
{
///This is mouse function
if(state=GLUT_DOWN) printf("glVertex2f( %.2f, %.2f);\n",(x-250)/250.0, -(y-250)/250.0);
}
void motion (int x, int y)
{
glColor3f( 1,x/500.0, y/500.0);///500 for window size
glutPostRedisplay(); ///display(); ///wrong!!!
}
void display()
{
glBegin(GL_POLYGON);
for(float angle=0;angle<3.14159*2;angle+=0.001)
{
glVertex2f(cos(angle),sin(angle));
glEnd();
glutSwapBuffers();
}
}
int main(int argc,char*argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("04160551 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);///test the mouse func
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言