2023年2月22日 星期三

week02_2點線面

 Week02

選擇New->Project
點選GLUT Project
選擇桌面,命名為week02_GLUT_first
桌面->2022葉正聖老師上課軟體->freeglut-MinGW-3.0.0-1.mp.zip->把freeglut拉到桌面
freeglut->lib->複製libfreeglut.a->檔名改成libglut32.a

畫大小茶壺
#include <GL/glut.h>
void display()
{
    glColor3f(0,1,0);///step01-2綠色
    glutSolidTeapot( 0.5 );///step01-2畫出一個實心大茶壺,它的大小為0.5   
    

    glColor3f(1,1,0);///step01-1黃色
    glutSolidTeapot( 0.3 );///step01-1畫出一個實心小茶壺,它的大小為0.3  
    glutSwapBuffers();///step01-1請GLUT把畫面swap送到顯示的地方
}
int main(int argc, char *argv[]) 
{///上面是特別的main()函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
//上面這行,把顯示設定好
glutCreateWindow("GLUT Shapes");//要開視窗
glutDisplayFunc(display);//要顯示對應函式
glutMainLoop();//最後用main迴圈,壓在最後面
}

畫三角形
#include <GL/glut.h>
void display()
{
    glColor3f(0,1,0);///step01-2綠色
    ///glutSolidTeapot( 0.5 );///step01-2畫出一個實心大茶壺,它的大小為0.5

     glBegin(GL_POLYGON);///開始畫多邊形
        glVertex2f( 0, 1);///頂點Vertex
        glVertex2f(-1,-1);///頂點Vertex
        glVertex2f( 1,-1);///頂點Vertex
     glEnd();///結束畫

    glColor3f(1,1,0);///step01-1黃色
    glutSolidTeapot( 0.3 );///step01-1畫出一個實心小茶壺,它的大小為0.3
    glutSwapBuffers();///step01-1請GLUT把畫面swap送到顯示的地方
}
int main(int argc, char *argv[]) 
{///上面是特別的main()函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
//上面這行,把顯示設定好
glutCreateWindow("GLUT Shapes");//要開視窗
glutDisplayFunc(display);//要顯示對應函式
glutMainLoop();//最後用main迴圈,壓在最後面
}
       
 step02-1把三角形上色
glColor3f(1,0,0);  glVertex2f( 0, 1);///紅色頂點Vertex
glColor3f(0,1,0);  glVertex2f(-1,-1);///綠色頂點Vertex
glColor3f(0,0,1);  glVertex2f( 1,-1);///藍色頂點Vertex
glEnd();///結束畫


step03-1畫圓
///week02-3_circle_cos_sin
#include <GL/glut.h>
#include <math.h>///cos()和sin()要用
void myCircle(float r,float x,float y)
{
    glBegin(GL_POLYGON);///step02-1開始畫多邊形
    for(float a = 0; a< 2*3.1415926; a+=0.01){
            glVertex2f( r*cos(a)+x, r*sin(a)+y );
        }
    glEnd();///step02-1結束畫
}
void display()
{
    glColor3f(1,0,1); myCircle( 0.6, 0, 0 );///正中間

    glColor3f(1,0,0); myCircle( 0.3, 0.5, 0.5 );///右上角
    glColor3f(0,1,0); myCircle( 0.3,-0.5, 0.5 );///左上角
    glColor3f(1,1,0); myCircle( 0.3,-0.5,-0.5 );///左下角
    glColor3f(0,0,1); myCircle( 0.3, 0.5,-0.5 );///右下角

    glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
int main(int argc, char *argv[])
{///上面是特別的main()函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);///上面這行,把顯示設定好
glutCreateWindow("GLUT Shapes");///要開視窗
glutDisplayFunc(display);///要顯示對應函式
glutMainLoop();///最後用main迴圈,壓在最後面
}









沒有留言:

張貼留言