到小葉老師的網站下載(http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/)
Examples: [data]、[win32]、glut32.dll>將[win32]解壓縮> 把[data]、glut32.dll、放進[win32]資料夾 > 打開範例Transformation.exe
<glut>
step
1.在瀏覽器搜尋freeglut windows 找到mingw下載
2.在lib內找到libfreeglut.a複製一個新的改成libglut32.a
3.打開codeblocks>file>new>project>glut project
4.在視窗輸入project title設定位置為C:\Users\user\Desktop\freeglut>finish
5.點擊management窗格的檔案main.cpp,執行build and run
<固定茶壺範例程式碼>
#include <GL/glut.h>void display()
{
glPushMatrix();///備份矩陣
glTranslatef(0.3,0.3,0);///移動(會改矩陣)
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣,才不會在下次有舊的殘值
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06161082");
glutDisplayFunc(display);
glutMainLoop();
}
<滑鼠移動茶壺範例程式碼>
#include <GL/glut.h>float x=0,y=0;///滑鼠motion
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef((x-150)/150.0,-(y-150)/150.0,0);///滑鼠motion
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣,才不會在下次有舊的殘值
glutSwapBuffers();
}
void motion(int nowX,int nowY)///滑鼠motion
{///滑鼠motion
x=nowX; y=nowY;
display();///滑鼠motion 更新
}///滑鼠motion
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06161082");
glutDisplayFunc(display);
glutMotionFunc(motion);///滑鼠motion
glutMainLoop();
}
沒有留言:
張貼留言