2023年2月23日 星期四

91 week02

 開 freeglut 壓縮檔再拉到桌面


\freeglut\lib裡libfreeglut.a複製成libglut32.a
開code blocks 選glut專案 名稱: week01-2_GLUT 把目錄改設成桌面的freeglut

最後執行

左邊Sources->main.cpp開啟
貼上:
#include <GL/glut.h>
void display()
{
    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();
}

執行結果:

第二個程式:
插入程式:
    glColor3f(1,1,0);//黃色
    glutSolidTeapot( 0.5 );//大茶壺
    glColor3f(0,1,0);//綠色
    glutSolidTeapot( 0.3 );//小茶壺
結果:
第二節課第一程式:
上個程式修改:
glColor3f(0,1,0);
    glBegin(GL_POLYGON);
        glVertex2f(0,1);//頂點
        glVertex2f(-1,-1);//頂點
        glVertex2f(+1,-1);//頂點
    glEnd();
    glColor3f(1,1,0);
    glutSolidTeapot( 0.3 );
    glutSwapBuffers();
結果:
第二堂第二程式:
修改並增加程式碼:
glBegin(GL_POLYGON);
         glColor3f(1,0,0); 顏色 glVertex2f(0,1);
         glColor3f(0,1,0); 顏色 glVertex2f(-1,-1);
         glColor3f(0,0,1); 顏色 glVertex2f(+1,-1);
    glEnd();
    glColor3f(1,1,0);
    glutSolidTeapot( 0.3 );
    glutSwapBuffers();
結果:
week02-3:
多邊形:
#include <GL/glut.h>
void display()
{
    glBegin(GL_POLYGON);
    glVertex2f((216-100)/100.0,-(13-100)/100.0);
    glVertex2f((144-100)/100.0,-(128-100)/100.0);
    glVertex2f((9-100)/100.0,-(157-100)/100.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week02");
    glutDisplayFunc(display);
    glutMainLoop();
}
增加色彩:
glColor3f(233/255.0,141/255.0,128/255.0);
    glBegin(GL_POLYGON);
    glVertex2f((216-100)/100.0,-(13-100)/100.0);
    glVertex2f((144-100)/100.0,-(128-100)/100.0);
    glVertex2f((9-100)/100.0,-(157-100)/100.0);
    glEnd();
    glutSwapBuffers();
week02-4:
修改程式(五圓圖):
#include <GL/glut.h>
#include <math.h>
void cir(float r,float x,float y)
{
    glBegin(GL_POLYGON);
    for(float a=0;a<=2*3.141592;a+=0.01){
        glVertex2f(r*cos(a)+x,r*sin(a)+y);
    }
    glEnd();
}
void display()
{
    glColor3f(233/255.0,141/255.0,128/255.0);
    cir(0.5,0,0);
    glColor3f(1,1,0);
    cir(0.3,0.5,0.5);
    glColor3f(1,0,0);
    cir(0.3,-0.5,0.5);
    glColor3f(0,1,0);
    cir(0.3,-0.5,-0.5);
    glColor3f(0,0,1);
    cir(0.3,0.5,-0.5);
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week02");
    glutDisplayFunc(display);
    glutMainLoop();
}
結果:







沒有留言:

張貼留言