2024年2月29日 星期四

binhun-week02

 上老師的網站

https://jsyeh.org/3dcg10/

下載

- data data.zip

- win32 windows.zip

解壓縮後將data放到windows裡面

開啟shapes


右鍵可以更改點線面

glColor3f 可以更改顏色每個頂點都可以有自己的色彩

glVertex2f 代表頂點位置

有三個頂點


右鍵可以切換大小頂點

第一個程式先下載freeglut 更改檔案名稱

開新專案

檔案名稱week02_glut_color_teapot

貼上上週10行程式

複製程式碼
                                       


可以用小畫家查看顏色的rgb裡面數值要/255.0
    glColor3f(211/255.0,111/255.0,120/255.0);
    glutSolidTeapot(0.3);
    glColor3f(50/255.0,66/255.0,200/255.0);
    glutSolidTeapot(0.2);

開新專案檔案名:week02_glut_trangle_color
glBegin(GL_POLYGON);//開始畫
        glColor3f(1,0,0); glVertex2f(0,1);
        glColor3f(0,1,0); glVertex2f(+1,-0.6);
        glColor3f(0,0,1); glVertex2f(-1,-0.6);
  glEnd();//結束畫


#include <GL/glut.h>
void display()
{
    glBegin(GL_POLYGON);///開始畫
        glColor3f(1,0,0); glVertex2f(0,1);
        glColor3f(0,1,0); glVertex2f(+1,-0.6);
        glColor3f(0,0,1); glVertex2f(-1,-0.6);
    glEnd();///結束畫
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week02_color_teapot");
    glutDisplayFunc(display);
    glutMainLoop();
}
用小畫家找頂點座標 口訣: 減一半、除一半、Y加負號
#include <GL/glut.h>
void display()
{
    glBegin(GL_POLYGON);///開始畫
        glVertex2f((34-200)/200.0, -(76-200)/200.0);
        glVertex2f((48-200)/200.0, -(131-200)/200.0);
        glVertex2f((85-200)/200.0, -(59-200)/200.0);
    glEnd();///結束畫
    glBegin(GL_POLYGON);///開始畫
        glVertex2f((383-200)/200.0, -(79-200)/200.0);
        glVertex2f((348-200)/200.0, -(146-200)/200.0);
        glVertex2f((312-200)/200.0, -(55-200)/200.0);
    glEnd();///結束畫
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week02_color_teapot");
    glutDisplayFunc(display);
    glutMainLoop();
}



#include <GL/glut.h>
#include <math.h>///數學函式庫
void myCircle(float x, float y, float r) {     glBegin(GL_POLYGON);         for(float a=0; a<=3.1415*2; a+=0.1){             glVertex2f(r*cos(a)+x, r*sin(a)+y);         }     glEnd(); } void display(){     myCircle(0.5 , 0.5 , 0.3);     myCircle(-0.5 , 0.5 , 0.3);     myCircle(0 , -0.1 , 0.6);     glutSwapBuffers(); } int main(int argc, char *argv[]) {     glutInit(&argc, argv);     glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);     glutCreateWindow("week02_color_teapot");     glutDisplayFunc(display);     glutMainLoop(); }



沒有留言:

張貼留言