2019年3月14日 星期四

Week04_玄的筆記

Week 04上課筆記

到此網址  http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

下載檔案  (已連結)  --> 並解壓縮到同一個資料夾
window.zip    




測試 是否可以開啟檔案  




確認可以開啟後  打開CodeBlock 開啟專案 Free GLUT

下載檔案 FreeGLUT  並壓縮 --> 到lib 資料夾 複製libfreeglut.a 並貼上
將檔名改成  libglut32.a


將Freeglut資料夾位址網址並貼上


成功開啟專案  並且 Build

將程式碼刪掉, 更改為下列
Translate() 為移動  (x,y,z) 為移動值

//////////////////
#include<GL/glut.h>

void  display()

{
    glPushMatrix();
        glColor3f(100,0,0); ///茶壺是紅色
        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("Shu的視窗");

    glutDisplayFunc(display);

    glutMainLoop();

}

///////////////

讓茶壺跟著滑鼠移動


///////
#include<GL/glut.h>
float x=0, y=0; ///滑鼠移動
void  display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix(); ///備份
        glColor3f(100,0,0); ///茶壺是紅色
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);
        glutSolidTeapot(0.3);
    glPopMatrix(); /// 還原
    glutSwapBuffers();

}
void motion(int nowX,int nowY)
{
    x=nowX; y=nowY;
    display(); /// 更新滑鼠位址
}
int main (int argc, char**argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Shu的視窗");
    glutDisplayFunc(display);
    glutMotionFunc(motion); ///滑鼠的motion

    glutMainLoop();

}
////




沒有留言:

張貼留言