下載:

再來複習前幾週的開啟GLUT檔案,要記得先將freeglut壓縮檔裡的資料夾移至桌面並且在lib裡面複製一份libfreeglut.a改檔名到libglut32.a。
對照原先的式子,縮短程式行數,寫出茶壺。

如何將滑鼠加入進去?

移動茶壺位置。
#include <GL/glut.h>
#include<stdio.h>
float teapotX=0, teapotY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y )
{
teapotX = (x-150)/150.0;
teapotY = -(y-150)/150.0;
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}

自己劃出一個你想要的圖如下。
利用點去作畫。
沒有留言:
張貼留言