


2.讓茶壺不會移動

程式碼:
#include <GL/glut.h>
float nowX=0, nowY=0;
void mouse(int button, int state, int x, int y)
{
nowX = (x-150)/150.0; nowY = -(y-150)/150.0;
}
void display()
{
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(nowX, nowY, 0);
glColor3f(1,0,0);
glutSolidTeapot (0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hellow3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
畫出黑色圓圈,髓移動滑鼠及可顯示座標

沒有留言:
張貼留言