2018年3月16日 星期五

week03 葉政翰

1.data.zip, windows.zip, glut32.dll 這3個檔案的網址在 http://jsyeh.org/3dcg10
2.把windows.zip解壓縮,並把 glut32.dll都進去解壓縮後的資料夾裡
3.並開始Shape.exe


這是Point模式~~


--------------------------------------------------------------------------------------------------------------------------
寫另外一種程式

#include <stdio.h>

#include <GL/glut.h>

///(1) 我們要使用比較高級的GLUT (OpengGL User Toolkit)

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清畫面

    glutSolidTeapot(0.3);///(9) 大小為0.3的茶壺

    glutSwapBuffers();///(10)交換double buffers 來顯示畫出來的畫面

}

int main(int argc, char **argv)///(2)主要的函式 main

{ /// 這個參數的意思,是把作育系統的參數,塞進來

    glutInit(&argc, argv);///(3)初始Initizlize你的glut參數設定

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///(4)顯示模式:double buffers (以後再教其他)

    glutCreateWindow("week03 Mouse");///(5)建立視窗

    glutDisplayFunc(display);///(6) 顯示函式display() 用來畫圖的

    glutMainLoop();///(7)主要的迴圈,用來控制程式

}


---------------------------------------------------------------------------------------------------------------------



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

///(1) 我們要使用比較高級的GLUT (OpengGL User Toolkit)

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清畫面
    glutSolidTeapot(0.3);///(9) 大小為0.3的茶壺
    glutSwapBuffers();///(10)交換double buffers 來顯示畫出來的畫面
}

void mouse(int button, int state, int x, int y)
{
   printf("%d %d %d %d\n", button, state, x, y);
}

int main(int argc, char **argv)///(2)主要的函式 main
{ /// 這個參數的意思,是把作育系統的參數,塞進來

    glutInit(&argc, argv);///(3)初始Initizlize你的glut參數設定
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///(4)顯示模式:double buffers (以後再教其他)
    glutCreateWindow("week03 Mouse");///(5)建立視窗
    glutDisplayFunc(display);///(6) 顯示函式display() 用來畫圖的
    glutMouseFunc(mouse);
    glutMainLoop();///(7)主要的迴圈,用來控制程式

}
-----------------------------------------------------------------------------------------------------------------------

可以標明點的程式


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

///(1) 我們要使用比較高級的GLUT (OpengGL User Toolkit)

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清畫面
    glutSolidTeapot(0.3);///(9) 大小為0.3的茶壺
    glutSwapBuffers();///(10)交換double buffers 來顯示畫出來的畫面
}

void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN) printf("  glVertex2f(%f, %f);\n", (x-150)/150.0, (150-y)/150.0);
    ///printf("%d %d %d %d\n", button, state, x, y);
}

int main(int argc, char **argv)///(2)主要的函式 main
{ /// 這個參數的意思,是把作育系統的參數,塞進來

    glutInit(&argc, argv);///(3)初始Initizlize你的glut參數設定
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///(4)顯示模式:double buffers (以後再教其他)
    glutCreateWindow("week03 Mouse");///(5)建立視窗
    glutDisplayFunc(display);///(6) 顯示函式display() 用來畫圖的
    glutMouseFunc(mouse);
    glutMainLoop();///(7)主要的迴圈,用來控制程式

}
--------------------------------------------------------------------------------------------------------------------------

可以拖曳物件的程式


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

///(1) 我們要使用比較高級的GLUT (OpengGL User Toolkit)
float teapotX=0, teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///(8)清畫面
    glPushMatrix();
        glTranslatef(teapotX, teapotY, 0);

    glutSolidTeapot(0.3);///(9) 大小為0.3的茶壺
    glPopMatrix();
    glutSwapBuffers();///(10)交換double buffers 來顯示畫出來的畫面
}

void mouse(int button, int state, int x, int y)
{
    ///if(state==GLUT_DOWN) printf("  glVertex2f(%f, %f);\n", (x-150)/150.0, (150-y)/150.0);
    ///printf("%d %d %d %d\n", button, state, x, y);
}
void motion(int x, int y)
{
    teapotX=(x-150)/150.0;teapotY=(150-y)/150.0;
    glutPostRedisplay();
}

int main(int argc, char **argv)///(2)主要的函式 main
{ /// 這個參數的意思,是把作育系統的參數,塞進來

    glutInit(&argc, argv);///(3)初始Initizlize你的glut參數設定
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///(4)顯示模式:double buffers (以後再教其他)
    glutCreateWindow("week03 Mouse");///(5)建立視窗
    glutDisplayFunc(display);///(6) 顯示函式display() 用來畫圖的
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();///(7)主要的迴圈,用來控制程式

}


沒有留言:

張貼留言