1.鵝黃色背景
2.旋轉茶壺
3.縮放茶壺
#include <GL/glut.h>
float angle=0;
float s=1;
void display()
{
glClearColor(1.0, 0.0, 0.9, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
///glRotatef(angle, 0, 0, 1);
glScalef(s,s,s);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
///angle=x;
s=1+(x-150)/150.0;
display();
}
int main(int argc, char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 mouse glScalef");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
4.非常好茶壺,使我旋轉
#include <GL/glut.h>
#include <stdio.h>
float angle=0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 0, 1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y){
oldX=x;///當mouse按時紀錄位置
}
void motion(int x, int y){
angle += (x-oldX);
oldX=x;
display();
}
void keyboard(unsigned char key, int x, int y)
{
printf("key: %c x: %d y: %d\n", key, x, y);
}
int main(int argc, char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 keyboard mouse botion");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
5.移動和旋轉
#include <GL/glut.h>
#include <stdio.h>
float angle=0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.8, 0, 0);
glRotatef(angle++, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04 keyboard mouse motion");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}






沒有留言:
張貼留言