1.普通的茶杯
#include <GL/glut.h>
#include <stdio.h>
int mouseX=0, mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(180,0,0,1);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit( &argc,argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week03");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
2.會轉的茶杯
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
angle = x;
display();
}
int main(int argc, char** argv)
{
glutInit( &argc,argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 Rotate");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
3.左右滑動的茶杯
#include <GL/glut.h>
float angle=0,oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int staste,int x,int y)
{
oldX = x;
}
void motion(int x,int y)
{
angle += (x-oldX);
oldX = x;
display();
}
int main(int argc, char** argv)
{
glutInit( &argc,argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 Rotate");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言