1.點,線,面,顏色
Vertex 頂點
glBegin(GL_POLYGON); //開始畫
glColor3f( R, G, B); //改顏色
glVertex2f( x, y ); //頂點
glEnd(); //結束畫
到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載: windows.zip, data.zip, glut32.dll (且將data&glut32.dll放入windows當中)
點名Veyon Config/服務/▶️啟動服務
glBegin(GL_POLYGON); //開始畫
glColor3f( R, G, B); //改顏色
glVertex2f( x, y ); //頂點
glEnd(); //結束畫
到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載: windows.zip, data.zip, glut32.dll (且將data&glut32.dll放入windows當中)
點名Veyon Config/服務/▶️啟動服務
2019 graphics Blog
2.實作
先做week01的第一個GLUT程式,在main.cpp內的程式碼全刪,改成以下程式碼
#include <GL/glut.h> ///使用GL/glut.h的外掛
void display(){
void display(){
glColor3f(0.0, 0.8, 0.5); //改顏色,必須在畫圖之前上色
glutSolidTeapot(0.3); //畫實心茶壺
glutSwapBuffers(); //最後buffer做交換秀出
}
int main(int argc,char**argv)
{
glutInit(&argc, argv); //初始啟動GLUT
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
//初始啟動GLUT的顯示模式,兩倍buffers,有3D深度
//初始啟動GLUT的顯示模式,兩倍buffers,有3D深度
glutCreateWindow("Week03"); //Create你的Window
glutDisplayFunc(display); //Display的函式是...display
glutMainLoop(); //主要迴圈
}
#include <GL/glut.h>
#include <math.h>
void display(){
glBegin(GL_POLYGON);///方幕
glColor3f(0.5, 0.50, 0.5);
glVertex2f( (0-100)/100.0, -(0-100)/100.0 );
glVertex2f( (200-100)/100.0, -(0-100)/100.0 );
glVertex2f( (200-100)/100.0, -(200-100)/100.0 );
glVertex2f( (0-100)/100.0, -(200-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///六幕
glColor3f(1.0, 1.0, 1.0);
glVertex2f( (200-100)/100.0, -(100-100)/100.0 );
glColor3f(0.0, 0.0, 1.0);
glVertex2f( (150-100)/100.0, -(0-100)/100.0 );
glColor3f(0.0, 1.0, 0.3);
glVertex2f( (50-100)/100.0, -(0-100)/100.0 );
glColor3f(0.9, 0.0, 0.9);
glVertex2f( (0-100)/100.0, -(100-100)/100.0 );
glColor3f(1.0, 0.0, 0.0);
glVertex2f( (50-100)/100.0, -(200-100)/100.0 );
glColor3f(1.0, 1.0, 0.0);
glVertex2f( (150-100)/100.0, -(200-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///中大外圓
glColor3f(0.0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/2, sin(a)/2+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中大內圓
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/2.39, sin(a)/2.39+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中直
glColor3f(0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/14, sin(a)/1.5+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中外圓
glColor3f(0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/7, sin(a)/7+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///中內圓
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.04){
glVertex2f( cos(a)/9, sin(a)/9+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///中內直
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/40, sin(a)/5+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///上箏型
glColor3f(1.0, 1, 1.0);
glVertex2f( (108-100)/100.0, -(12-100)/100.0 );
glColor3f(0.0, 0.00, 0.0);
glVertex2f( (100-100)/100.0, -(5-100)/100.0 );
glColor3f(1.0, 1.00, 1.0);
glVertex2f( (92-100)/100.0, -(12-100)/100.0 );
glColor3f(0.0, 0.00, 0.0);
glVertex2f( (100-100)/100.0, -(20-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///下箏型
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (104-100)/100.0, -(176-100)/100.0 );
glVertex2f( (100-100)/100.0, -(162-100)/100.0 );
glVertex2f( (96-100)/100.0, -(176-100)/100.0 );
glVertex2f( (100-100)/100.0, -(193-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左下翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (79-100)/100.0, -(115-100)/100.0 );
glVertex2f( (56-100)/100.0, -(129-100)/100.0 );
glVertex2f( (48-100)/100.0, -(145-100)/100.0 );
glVertex2f( (32-100)/100.0, -(165-100)/100.0 );
glVertex2f( (57-100)/100.0, -(153-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右下翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(79-100)/100.0, -(115-100)/100.0 );
glVertex2f( -(56-100)/100.0, -(129-100)/100.0 );
glVertex2f( -(48-100)/100.0, -(145-100)/100.0 );
glVertex2f( -(32-100)/100.0, -(165-100)/100.0 );
glVertex2f( -(57-100)/100.0, -(153-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左中翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (83-100)/100.0, -(98-100)/100.0 );
glVertex2f( (58-100)/100.0, -(100-100)/100.0 );
glVertex2f( (15-100)/100.0, -(114-100)/100.0 );
glVertex2f( (6-100)/100.0, -(111-100)/100.0 );
glVertex2f( (40-100)/100.0, -(117-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右中翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(83-100)/100.0, -(98-100)/100.0 );
glVertex2f( -(58-100)/100.0, -(100-100)/100.0 );
glVertex2f( -(15-100)/100.0, -(114-100)/100.0 );
glVertex2f( -(6-100)/100.0, -(111-100)/100.0 );
glVertex2f( -(40-100)/100.0, -(117-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左上翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (80-100)/100.0, -(87-100)/100.0 );
glVertex2f( (53-100)/100.0, -(70-100)/100.0 );
glVertex2f( (26-100)/100.0, -(66-100)/100.0 );
glVertex2f( (6-100)/100.0, -(60-100)/100.0 );
glVertex2f( (25-100)/100.0, -(82-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右上翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(80-100)/100.0, -(87-100)/100.0 );
glVertex2f( -(53-100)/100.0, -(70-100)/100.0 );
glVertex2f( -(26-100)/100.0, -(66-100)/100.0 );
glVertex2f( -(6-100)/100.0, -(60-100)/100.0 );
glVertex2f( -(25-100)/100.0, -(82-100)/100.0 );
glEnd();
glutSwapBuffers();
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160193_Week03_作業");
glutDisplayFunc(display);
glutMainLoop();
}
#include <math.h>
void display(){
glBegin(GL_POLYGON);///方幕
glColor3f(0.5, 0.50, 0.5);
glVertex2f( (0-100)/100.0, -(0-100)/100.0 );
glVertex2f( (200-100)/100.0, -(0-100)/100.0 );
glVertex2f( (200-100)/100.0, -(200-100)/100.0 );
glVertex2f( (0-100)/100.0, -(200-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///六幕
glColor3f(1.0, 1.0, 1.0);
glVertex2f( (200-100)/100.0, -(100-100)/100.0 );
glColor3f(0.0, 0.0, 1.0);
glVertex2f( (150-100)/100.0, -(0-100)/100.0 );
glColor3f(0.0, 1.0, 0.3);
glVertex2f( (50-100)/100.0, -(0-100)/100.0 );
glColor3f(0.9, 0.0, 0.9);
glVertex2f( (0-100)/100.0, -(100-100)/100.0 );
glColor3f(1.0, 0.0, 0.0);
glVertex2f( (50-100)/100.0, -(200-100)/100.0 );
glColor3f(1.0, 1.0, 0.0);
glVertex2f( (150-100)/100.0, -(200-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///中大外圓
glColor3f(0.0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/2, sin(a)/2+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中大內圓
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/2.39, sin(a)/2.39+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中直
glColor3f(0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/14, sin(a)/1.5+0.08 );
}
glEnd();
glBegin(GL_POLYGON);///中外圓
glColor3f(0, 0.8, 1.0);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/7, sin(a)/7+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///中內圓
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.04){
glVertex2f( cos(a)/9, sin(a)/9+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///中內直
glColor3f(0.4, 0.4, 0.4);
for(float a=0;a<3.14159*2;a+=0.05){
glVertex2f( cos(a)/40, sin(a)/5+0.02 );
}
glEnd();
glBegin(GL_POLYGON);///上箏型
glColor3f(1.0, 1, 1.0);
glVertex2f( (108-100)/100.0, -(12-100)/100.0 );
glColor3f(0.0, 0.00, 0.0);
glVertex2f( (100-100)/100.0, -(5-100)/100.0 );
glColor3f(1.0, 1.00, 1.0);
glVertex2f( (92-100)/100.0, -(12-100)/100.0 );
glColor3f(0.0, 0.00, 0.0);
glVertex2f( (100-100)/100.0, -(20-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///下箏型
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (104-100)/100.0, -(176-100)/100.0 );
glVertex2f( (100-100)/100.0, -(162-100)/100.0 );
glVertex2f( (96-100)/100.0, -(176-100)/100.0 );
glVertex2f( (100-100)/100.0, -(193-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左下翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (79-100)/100.0, -(115-100)/100.0 );
glVertex2f( (56-100)/100.0, -(129-100)/100.0 );
glVertex2f( (48-100)/100.0, -(145-100)/100.0 );
glVertex2f( (32-100)/100.0, -(165-100)/100.0 );
glVertex2f( (57-100)/100.0, -(153-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右下翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(79-100)/100.0, -(115-100)/100.0 );
glVertex2f( -(56-100)/100.0, -(129-100)/100.0 );
glVertex2f( -(48-100)/100.0, -(145-100)/100.0 );
glVertex2f( -(32-100)/100.0, -(165-100)/100.0 );
glVertex2f( -(57-100)/100.0, -(153-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左中翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (83-100)/100.0, -(98-100)/100.0 );
glVertex2f( (58-100)/100.0, -(100-100)/100.0 );
glVertex2f( (15-100)/100.0, -(114-100)/100.0 );
glVertex2f( (6-100)/100.0, -(111-100)/100.0 );
glVertex2f( (40-100)/100.0, -(117-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右中翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(83-100)/100.0, -(98-100)/100.0 );
glVertex2f( -(58-100)/100.0, -(100-100)/100.0 );
glVertex2f( -(15-100)/100.0, -(114-100)/100.0 );
glVertex2f( -(6-100)/100.0, -(111-100)/100.0 );
glVertex2f( -(40-100)/100.0, -(117-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///左上翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( (80-100)/100.0, -(87-100)/100.0 );
glVertex2f( (53-100)/100.0, -(70-100)/100.0 );
glVertex2f( (26-100)/100.0, -(66-100)/100.0 );
glVertex2f( (6-100)/100.0, -(60-100)/100.0 );
glVertex2f( (25-100)/100.0, -(82-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);///右上翼
glColor3f(0.0, 0.8, 1.0);
glVertex2f( -(80-100)/100.0, -(87-100)/100.0 );
glVertex2f( -(53-100)/100.0, -(70-100)/100.0 );
glVertex2f( -(26-100)/100.0, -(66-100)/100.0 );
glVertex2f( -(6-100)/100.0, -(60-100)/100.0 );
glVertex2f( -(25-100)/100.0, -(82-100)/100.0 );
glEnd();
glutSwapBuffers();
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("06160193_Week03_作業");
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言