打開GLUT 詳情看week01
複製以下程式碼
#include <GL/glut.h>
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
}
接著刪除全部程式碼
再加上
void display()
{
glutSolidTeapot(0.3); ///劃出一個實心的茶壺 大小0.3
glutSwapBuffers(); /// GLUT把畫面swap送到顯示的地方
}
輸入 glColor3f(1,1,0); 上色
以此類推
把 glutSolidTeapot(0.5); 刪掉 加上頂點
glBegin(GL_POLYGON);
glVertex2f(0,1);
glVertex2f(-1,-1);
glVertex2f(+1,-1);
glEnd();
刪除 glColor3f(0,1,0);
改成
glColor3f(1,0,0); glVertex2f(0,1); 紅色頂點
glColor3f(0,1,0); glVertex2f(-1,-1); 綠色頂點
glColor3f(0,0,1); glVertex2f(+1,-1); 藍色頂點
四邊形
#include <GL/glut.h>
void display()
{
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();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
}
五個圓
#include <GL/glut.h>
#include <math.h>
void myCircle(float r,float x,float y) 畫圓
{
glBegin(GL_POLYGON);
for(float a=0;a<2*3.14;a+=0.01){
glVertex2f(r*cos(a)+x,r*sin(a)+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();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
}






沒有留言:
張貼留言