2017年3月7日 星期二

week03太詳細啦~~

一.
跟上週一樣先去FB載freeglut.zip

到jsyeh.org/3dcg10下載這3個檔案
data.zip
windows.zip
glut32.dll

解壓縮windows在桌面
將data解壓縮進windows
glut32也放進windows中
freeglut也是


用codeblocks打開glut計畫
並將程式碼縮至10行
#include<GL/glut.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);//畫茶壺
    glutSwapBuffers();
}
int main(int argc,char * argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
    return EXIT_SUCCESS;
}
並加入glColor3f(0.0,0.0,0.0);
變成
#include<GL/glut.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(0.0,0.0,0.0);  
    glutSolidTeapot(0.3);//畫茶壺
    glutSwapBuffers();
}
int main(int argc,char * argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
    return EXIT_SUCCESS;
}

茶壺就會變色
二.
畫出彩色三角形
#include<GL/glut.h>
static void display(void)
{
    glBegin(GL_POLYGON);
        glColor3f(1,0,0);//顏色(R,G,B)
        glVertex3f(0,0,0);//頂點(x,y,z)

        glColor3f(0,1,0);
        glVertex3f(1,1,0);

        glColor3f(0,0,1);
        glVertex3f(1,-1,0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc,char * argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();
    return EXIT_SUCCESS;
}

沒有留言:

張貼留言