滑鼠的引入程式
void mouse(int button, int state, int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
}
glutMouseFunc(mouse);
這兩行程式用來引入操作滑鼠的程式
因為裡面需要用到 print
所以要引入#include <stdio.h>
--------------------------------------------------------------------------------------------------------------------------
滑鼠移動茶壺
點選可以移動茶壺
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX ,teapotY, 0);
glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
--------------------------------------------------------------------------------------------------------繪圖
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f((227-150)/150.0, -(132-150)/150.0);
glVertex2f((151-150)/150.0, -(115-150)/150.0);
glVertex2f((85-150)/150.0, -(141-150)/150.0);
glVertex2f((118-150)/150.0, -(188-150)/150.0);
glVertex2f((180-150)/150.0, -(186-150)/150.0);
glEnd();
glutSwapBuffers();
}
這幾個程式碼,是繪製五角形的程式碼
中間的5行是5角形的頂點座標





沒有留言:
張貼留言