Week02_GLUT
#include <GL/glut.h>
void display()
{
glutSolidTeapot( 0.3 ); ///畫出一個實心的茶壺 它的大小0.3
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迴圈 壓在最後面
}
glColor3f(0,1,0); ///綠色
畫三角形
glColor3f(0,1,0); ///綠色
glBegin(GL_POLYGON);///開始畫多邊形
glVertex2f( 0, 1); ///頂點Vertex
glVertex2f(-1,-1); ///頂點Vertex
glVertex2f(+1,-1); ///頂點Vertex
glEnd();///結束畫
glColor3f(1,0,0); glVertex2f( 0, 1); ///紅色的頂點Vertex
glColor3f(0,1,0); glVertex2f(-1,-1); ///綠色的頂點Vertex
glColor3f(0,0,1); glVertex2f(+1,-1); ///藍色的頂點Vertex
皮卡丘肚子
用小畫家,幫忙寫 設成200x200的圖片
0...200 -100...+100 左下角可看座標,再換算一下
glColor3f(247/255.0, 247/255.0, 247/255.0);
glBegin(GL_POLYGON);
glVertex2f( 1, 1);
glVertex2f( -1, 1);
glVertex2f( -1, -1);
glVertex2f( 1, -1);
glEnd();
glColor3f(244/255.0, 209/255.0, 33/255.0);
glBegin(GL_POLYGON);
glVertex2f( (45-100)/100.0, -(134-100)/100.0 );
glVertex2f( (36-100)/100.0, -(171-100)/100.0);
glVertex2f( (108-100)/100.0, -(179-100)/100.0);
glVertex2f( (104-100)/100.0, -(117-100)/100.0);
glEnd();///結束畫
///口訣:減一半、除一半、y變負號
glutSwapBuffers();
#include <GL/glut.h>
#include <math.h> ///cos() sin()要用
void myCircle(float r,float x,float y)
{
glBegin(GL_POLYGON);///開始畫多邊形
for(float a=0; a<2*3.141592653589793238462632383279; a+=0.01)
{
glVertex2f( r*cos(a)+x, r*sin(a)+y); ///r是半徑,x跟y是座標
}
glEnd();///結束畫
}
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送到顯示的地方
}
沒有留言:
張貼留言