2018年3月5日 星期一

Week 02 潘家智的筆記

http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載 data win32 glut32.dll放到同一資料夾解壓縮

執行 shape.exe
右鍵可選形狀 左鍵拖移可改變數值

glColor3f(r,g,b);
gl是OpenGL的函式
color色彩 3個參數
f float浮點數 0.0-1.0
ub unisgned char 0-255

glVertex2f(x,y);
gl 是openGl的函式
Vertex頂點  2個參數f float

漸層三角形
#include <GL/glut.h>
static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLES);

                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(0.0f,   1.0f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(0.87f,  -0.5f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(-0.87f, -0.5f);

            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;
}


茶壺
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutCreateWindow("05160320_Week02");

    glutDisplayFunc(display);
    glutMainLoop();
}

加入glColor3f(1,1,0); 改變茶壺顏色




漸層三角形
#include <GL/glut.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);  開始畫
        glColor3f(1,0,0);  色彩
        glVertex2d(0,1);  頂點
        glColor3f(0,1,0);
        glVertex2d(1,0);
        glColor3f(0,0,1);
        glVertex2d(-1,0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutCreateWindow("05160320_Week02");

    glutDisplayFunc(display);
    glutMainLoop();


}

沒有留言:

張貼留言