
(第2行 ) include <stdio.h>為了執行print。
(第8行):Button代表按著的滑鼠鍵,state代表上下。
(第19行):執行void(mouse)。
(第3行):呼叫 (-1.0) ~ (+1.0) 座標。
(第6行):清空背景。
(第8行):移動茶壺座標。
(第16.17行):讓x的0....300變成-1.....+1
:讓y的300....0變成-1.....+1
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float teapotX=0,teapotY=0;
void display()
{
glClearColor(255/255.0,255/255.5,255/255.0,1);//背景
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f((144/255.0),(86/255.0),(63/255.0));//咖啡
glBegin(GL_POLYGON);
glVertex2f( (80-150)/150.0, -(116-150)/150.0);
glVertex2f( (98-150)/150.0, -(187-150)/150.0);
glVertex2f( (207-150)/150.0, -(187-150)/150.0);
glEnd();
glColor3f((144/255.0),(86/255.0),(63/255.0));
glBegin(GL_POLYGON);
glVertex2f( (120-150)/150.0, -(146-150)/150.0);
glVertex2f( (148-150)/150.0, -(77-150)/150.0);
glVertex2f( (207-150)/150.0, -(187-150)/150.0);
glEnd();
glColor3f((144/255.0),(86/255.0),(63/255.0));
glBegin(GL_POLYGON);
glVertex2f( (207-150)/150.0, -(187-150)/150.0);
glVertex2f( (215-150)/150.0, -(109-150)/150.0);
glVertex2f( (179-150)/150.0, -(143-150)/150.0);
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));//黃色
glBegin(GL_POLYGON);
glVertex2f( (94-150)/150.0, -(136-150)/150.0);
glVertex2f( (105-150)/150.0, -(177-150)/150.0);
glVertex2f( (200-150)/150.0, -(177-150)/150.0);
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));
glBegin(GL_POLYGON);
glVertex2f( (125-150)/150.0, -(171-150)/150.0);
glVertex2f( (148-150)/150.0, -(104-150)/150.0);
glVertex2f( (196-150)/150.0, -(176-150)/150.0);
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));
glBegin(GL_POLYGON);
glVertex2f( (204-150)/150.0, -(133-150)/150.0);
glVertex2f( (175-150)/150.0, -(157-150)/150.0);
glVertex2f( (198-150)/150.0, -(177-150)/150.0);
glEnd();
glColor3f((144/255.0),(86/255.0),(63/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.05*cos(angle)-0.5,0.05*sin(angle)+0.3);
}
glEnd();
glColor3f((144/255.0),(86/255.0),(63/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.05*cos(angle),0.05*sin(angle)+0.6);
}
glEnd();
glColor3f((144/255.0),(86/255.0),(63/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.05*cos(angle)+0.5,0.05*sin(angle)+0.4);
}
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.03*cos(angle)-0.5,0.03*sin(angle)+0.3);
}
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.03*cos(angle),0.03*sin(angle)+0.6);
}
glEnd();
glColor3f((255/255.0),(238/255.0),(120/255.0));
glBegin(GL_POLYGON);
for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
{
glVertex2f(0.03*cos(angle)+0.5,0.03*sin(angle)+0.4);
}
glEnd();
glutSwapBuffers();
}
void mouse(int button,int state, int x,int y){
if(state==GLUT_DOWN){
printf(" glVertex2f( (%d-150)/150.0, -(%d-150)/150.0);\n",x,y);
}
}
int main(int argc,char ** argv)
{
glutInit( &argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week03");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}


沒有留言:
張貼留言