2018年6月24日 星期日

Week 03 潘家智的筆記

(1)先從這個網址http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載data.zip, windows.zip, glut32.dll 3個檔案


解壓縮windows.zip之後把glut32.dll複製進去
然後就可以執行shapes.exe

(2)再開啟codeblock glut專案並且畫出茶壺
 增加滑鼠按下去就能顯示x,y座標的程式


增加程式碼讓座標以程式碼呈現執行後點出每個點

#include <GL/glut.h>
/*float teapotX=0,teapotY=0;*/
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   /* glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();*/
    glutSwapBuffers();
}
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);

}
/*void motion(int x,int y)
{
    teapotX=(x-150)/150.0;
    teapotY=-(y-150)/150.0;
    printf("%d %d\n",x,y);
    glutPostRedisplay();

}*/
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("05160320_week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}

在程式執行框案右鍵全選後再按一次選擇複製

再重新貼到程式碼內




沒有留言:

張貼留言