2018年3月9日 星期五

Week02_吳幸俞

今天的第一個GLUT程式
(1)開啟Code::Blocks新增一個GLUT專案

(2)全選程式碼後刪除,並打上:
#include <stdio.h>
#include <GL/glut.h>
int main(int argc,char **argv)///意思是把作業系統的參數塞進來
{
    for(int i=0;i<argc;i++)
    {
        printf("argv[%d]: %s\n",i, argv[i]);///參數的字串的值
    }
}
(3)開啟freeglut資料夾底下的bin資料夾,複製freeglut.dll檔案到專案資料夾底下的bin->Debug資料夾貼上
(4)開啟cmd到專案資料夾路徑,依序打入程式碼後開啟專案程式打上要的字串
Microsoft Windows [版本 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\student>cd Desktop\1\bin\Debug

C:\Users\student\Desktop\1\bin\Debug>1.exe This is a book.
argv[0]: 1.exe///結果
argv[1]: This
argv[2]: is
argv[3]: a
argv[4]: book.

C:\Users\student\Desktop\1\bin\Debug>
今天的第二個GLUT程式---畫茶壺
(1)開啟Code::Blocks新增GLUT專案
(2)打上以下程式碼
#include <stdio.h>
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);///清畫面
    glutSolidTeapot(0.5);///大小為0.5的茶壺
    glutSwapBuffers();///交換double buffers來顯示畫出來的畫面
}
int main(int argc,char **argv)///這個參數的意思是把作業系統的參數塞進來
{
    glutInit(&argc,argv);///初始Initialize你的glut參數設定
    glutInitDisplayMode(GLUT_DOUBLE);///顯示模式:double buffers(以後再教)
    glutCreateWindow("WEEK2 teapot");///建立新的視窗及視窗標題

    glutDisplayFunc(display);///顯示函式display()*用來畫圖的
    glutMainLoop();///主要的迴圈,用來控制程式
}

沒有留言:

張貼留言