2019年3月8日 星期五

Week 03 _ 06163011

(一)
解壓縮 windows 及 date
複製 glut32.dll 到 windows 資料夾
date 資料夾 移到 windows 資料夾


打開 Transformation
點選圖片右鍵可切換圖案
更改數值可以調整方向、位置

(二)

搜尋 freeglut windows
👉 freeglut Windows Development Libraries - Transmission Zero













打開freeglut lib 複製 (1) libfreeglut.a並改名為 (2)libglut32.a
按照上週教的打開 code blocks 新增project 新增GLUT

先將main.cpp的內容刪除
並貼上以下:
#include <GL/glut.h>
void display()
{
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc, char ** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow(" Week02GLU哦 ");
    glutDisplayFunc(display);
    glutMainLoop();
}


新增:glTranslatef(0.2,0.2,0); 
glutCreateWindow(" Week03 translate ");


(三)

#include <GL/glut.h>
void display()
{
    glPushMatrix(); ///10% 備份矩陣,保護好
        glBegin(GL_POLYGON);  ///40%開始畫
            glColor3f(0.9,0,0.3); ///50%顏色
            glVertex2f(0.4,0.4); ///60%頂點
            glVertex2f(0.4,-0.4);
            glVertex2f(-0.4,-0.4);
            glVertex2f(-0.4,0.4);
    glEnd(); ///結束畫
    glTranslatef(0.2,0.2,0); ///20% Ttranslate移動x,y,z, f浮點數
    glColor3f(0,0,1);
    glutSolidTeapot( 0.3 );
    glPopMatrix();///30%還原矩陣,保護好
    glutSwapBuffers();
}
int main(int argc, char ** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03 translate");
    glutDisplayFunc(display);
    glutMainLoop();
}


(四)移動

#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();     ///你要把座標換算正確,(X-中間點)/最大值.0
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);
        glutSolidTeapot( 0.3 );

    glPopMatrix();
    glutSwapBuffers();
}  ///glut開頭,表示是GLUT的程式
void motion (int nowx, int nowy)
{
    x=nowx; y=nowy;   ///更新x,y
    display();  ///再畫display(),畫面會更新,他就會跟著你動(mouse去拖他)
}
int main(int argc, char ** argv)
{
    glutInit( &argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03 translate");
    glutDisplayFunc(display);
    glutMotionFunc(motion);  ///mouse有動作時
    glutMainLoop();
}





沒有留言:

張貼留言