2015年3月12日 星期四

胡佩君_week 03

1.     去 jsyeh.org/3dcg10 下載東西
2.    把東西都解壓縮 把環境設置好

3.       試試範例 shape

4.      可變換成圖形式

5.       接著打開Code::Blacks

6.        開一個新的glut cbp

7.      再來幫上禮拜的茶壺上顏色



#include <GL/glut.h>///呼叫外掛#include GL/glut的功能
void display()
{
    glColor3f(1,0,1);   // 三顏色  浮點數
    glutSolidTeapot(0.5);

    glFlush();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);///3.把glut準備好,參數照舊
    glutCreateWindow("拉拉得冠軍");///建置視窗(小駱駝命名法)
    glutDisplayFunc(display);
    glutMainLoop();///glut的主要迴圈,卡住用的

}




8.      重疊圖形

#include <GL/glut.h>///呼叫外掛#include GL/glut的功能
void display()
{
    glColor3f(1,0,0);
    glutSolidTeapot(0.5);

    glColor3f(0,1,0);
    glutSolidTeapot(0.4);

    glColor3f(0,0,1);
    glutSolidTeapot(0.3);

    glFlush();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);///3.把glut準備好,參數照舊
    glutCreateWindow("拉拉得冠軍");///建置視窗(小駱駝命名法)
    glutDisplayFunc(display);
    glutMainLoop();///glut的主要迴圈,卡住用的

}





P.S.    
可加入

    glColor3f(1,0,0);
    glutSolidTeapot(0.5);
    glColor3f(0,1,0);
    glutSolidTeapot(0.6);
    glColor3f(0,0,1);
    glutSolidTeapot(0.7);
程式碼出現多個不同大小的茶壺及顏色





(在display()增加程式: glClearColor(r,g,b,a); //換上什麼顏色
                                  glClear(GL_COLOR_BUFFER_BIT);//哪個背景刷上這個顏色)


(在display()增加程式 :glBegin(GL_POLYGON);//polygon:多邊形
                                  glColor3f(r,g,b);//換上顏色
                                  glVertex2f(x,y);//Vertex2f:頂點座標(float))





#include <GL/glut.h>///呼叫外掛#include GL/glut的功能
void display()
{
    glClearColor(0,0.3,0.6,1); //用來Clear清的顏色是捨麼
    glClear(GL_COLOR_BUFFER_BIT);//Clear  buffer

    glColor3f(1,0,0);
    glutSolidTeapot(0.5);
    //glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0,1,0);
    glutSolidTeapot(0.4);
    //glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0,0,1);
    glutSolidTeapot(0.3);
    //glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);///3.把glut準備好,參數照舊
    glutCreateWindow("拉拉得冠軍");///建置視窗(小駱駝命名法)
    glutDisplayFunc(display);
    glutMainLoop();///glut的主要迴圈,卡住用的

}




9.     畫圖形

#include <GL/glut.h>
void display()
{
    glClearColor(0.7,0,1,6);                            ///重點3.用來Clear清的顏色是什麼
    glClear(GL_COLOR_BUFFER_BIT);    ///重點2.Clear說明你清哪一個Buffer

    glBegin(GL_POLYGON);
        glColor3f(1,1,0);                                  ///今天的重點1.有顏色的茶壺
        glVertex2f(0,0);
        glVertex2f(1,0);
        glVertex2f(0,1);
    glEnd();
    glBegin(GL_POLYGON);
        glColor3f(1,0,0);
        glVertex2f(0,0);

        glColor3f(0,1,0);
        glVertex2f(-1,0);

        glColor3f(0,0,1);
        glVertex2f(0,-1);

    glEnd();
    glFlush();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("58拉拉得冠軍");
    glutDisplayFunc(display);
    glutMainLoop();
}




沒有留言:

張貼留言