
2.老師教我們把茶壺的顏色跟背景的顏色改掉
#include <GL/glut.h>///使用glut外掛
void display()
{
glClearColor(1,1,0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///2種模式
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();///交換書面BUFFER便會顯示
}
#include<stdio.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);
}
int main(int argc, char**argv)//進階的main()參數(個字,字串)
{
glutInit(&argc, argv);///近接參數,
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03 Mouse操作");
glutDisplayFunc(display);
glutMouseFunc(mouse);
///glutMotionFunc(motion);
glutMainLoop();
}

3.這個是教我們怎麼拖曳茶壺~
#include <GL/glut.h>///使用glut外掛
float teapotX=0, teapotY=0;///茶壺的位址一開始在0,0
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///2種模式
glPushMatrix();
glTranslatef(teapotX, teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();///交換書面BUFFER便會顯示
}
#include<stdio.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);
///把大象放到冰箱:(1)打開冰箱門(3)關冰箱門
}
void motion(int x, int y)///(2)把大象放進冰箱
{
teapotX=(x-150)/150.0;teapotY=-(y-150)/150.0;///把你的老鼠的位置設成茶壺的位置
printf("%d %d\n",x,y);///印出移動的數字
glutPostRedisplay();
}
int main(int argc, char**argv)//進階的main()參數(個字,字串)
{
glutInit(&argc, argv);///近接參數,
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///開啟兩種模式
glutCreateWindow("Week03 Mouse操作");///最好不要用中文
glutDisplayFunc(display);//等一下樓上要準備void display()
glutMouseFunc(mouse);///等一下也會準備好mosue()的功能按鈕
glutMotionFunc(motion);///等一下也會準備好motion(),移動
glutMainLoop();///主要迴圈
}

沒有留言:
張貼留言