2017電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2017年6月30日 星期五
2017年5月15日 星期一
2017年5月8日 星期一
Week12 陳18
1.http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 下載data.zip和windows.zip和glut32.dll
解壓縮至桌面並把data與glut32.dll放置windows裡
2.04160011_hw1_projection.zip改gluLookAt(......)
解壓縮至桌面並把data與glut32.dll放置windows裡
執行projection.exe 可自由調整數值
glutLookAt(eyeX,eyeY,eyeZ)攝影機
2.04160011_hw1_projection.zip改gluLookAt(......)
3.改gluPerspctive(for視野角,l,near,far)
2017年5月1日 星期一
Week11 陳18
1.google: 3D exploration(3D的檔案總管)
3D Exploration 1.81(橘色免費試用版)
3D Exploration 1.81(橘色免費試用版)
到jsyeh.org/3dcg10下載data.zip有3D模型可用(解壓縮至桌面)
接著到3D Exploration 打開user ->下載 - >data -> Soccerball.obj
File -> Save as ->點選cpp.open GL ->存檔
選取Sample APP -> ok 即完成
2.開啟Codeblocks (File ->New ->Project ->Open GL專案)
main.cpp右鍵Remove file from project
偷天換日(把main.cpp刪除)
找到剛剛存的檔案(在桌面) 複製檔案路徑C:\Users\user\Desktop\04160134
到3D Exploration找儲存的檔案並把它移到資料夾
到codeblocks右邊右鍵Add files
並將它打開
執行會有Debug將那行刪除
即可執行此程式
3.至http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載source.
解壓縮至桌面,到3D exploration ->user ->下載 -> data -> 打開dolphins.obj並取消
dolph02及dolph03勾選
2017年4月24日 星期一
Week10 陳18
1.玩遊戲(射擊)
google:HeNe Lesson 32
下載Lesson32最下面的Visual C++的範例並解壓縮至桌面.
google:HeNe Lesson 32
打開lesson32.exe
就可以開始玩遊戲了!!!!
2.模仿:File-New-Projects.GLUT
加入#include<mmsystem.h> //多媒體系統
void mouse(int button,int state,int x,int y)
{
PlaySound("C:\\users\\Desktop\\Lesson32\\data/shot.wav",NULL,SND_ASYNC);
}
glutMouseFunc(mouse); //Add a mouse Function
p.s是有聲音的哦
3.下載do,re,mi,fa,so音檔
程式碼反黃的是多加上去的
void keyboard(unsigned char key, int x, int y)
{
if(key=='1')PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/do.wav",NULL,SND_ASYNC);
if(key=='2')PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/re.wav",NULL,SND_ASYNC);
if(key=='3')PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/mi.wav",NULL,SND_ASYNC);
if(key=='4')PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/fa.wav",NULL,SND_ASYNC);
if(key=='5')PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/so.wav",NULL,SND_ASYNC);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
完成後就執行,也是會有聲音的哦!!!
2017年4月17日 星期一
Week09 陳18
1.複習上週
(1)data.zip到桌面\window\data\模型.mtl
(2)window.zip到桌面\window\Transformation.exe
(3)glut32.dll到桌面\window\glut32.dll
(4)把 window 檔案開啟並合併data, glut32.dll 檔案到裡面
2017年4月10日 星期一
Week08 陳18
1.複習期中考考題
glPushMatrix();///備份矩陣 10%
glTranslatef(x,y,x);///移動 30%
glRotatef(angle, x,y,z);///旋轉 40%
glScalef(x,y,z);///縮放 50%
glBegin(GL_POLYGON);///開始畫 60%
glColor3f(r,g,b);///顏色 70%
glNormal3f(nx,ny,nz);///打光法向量 90%
glTexCoord2f(tx,ty); ///貼圖座標 100%
glVertex3f(x,y,z);///頂點 80%
glEnd();///結束
glPopMatrix();///還原矩陣 20%
2.T-R-T轉動
#include <GL/glut.h>
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
多了 glutSolidCube(0.8);此行程式碼
glPushMatrix();///備份矩陣 10%
glTranslatef(x,y,x);///移動 30%
glRotatef(angle, x,y,z);///旋轉 40%
glScalef(x,y,z);///縮放 50%
glBegin(GL_POLYGON);///開始畫 60%
glColor3f(r,g,b);///顏色 70%
glNormal3f(nx,ny,nz);///打光法向量 90%
glTexCoord2f(tx,ty); ///貼圖座標 100%
glVertex3f(x,y,z);///頂點 80%
glEnd();///結束
glPopMatrix();///還原矩陣 20%
2.T-R-T轉動
#include <GL/glut.h>
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
3.打光
更改此行反藍部分的數值
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
4.旋轉
((反橘的部分是有更改的
#include <GL/glut.h>
float angle=0;
static void display(void)
{
angle++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0, 0.6, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glPushMatrix();
glRotatef(angle, 0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutIdleFunc(display);
glutDisplayFunc(display);
glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
5.機器人
2017年3月27日 星期一
Week05 陳18
1. 期中考重點
2.複習上週
2.複習上週
(1)data.zip到桌面\window\data\模型.mtl
(2)window.zip到桌面\window\Transformation.exe
(3)glut32.dll到桌面\window\glut32.dll
(4)把 window 檔案開啟並合併data, glut32.dll 檔案到裡面
(5)執行Transfomation 檔案
3.程式碼
glRotatef(90,0.5,0,0);
註:
(1)
大拇指往上,代表Y軸為正向,得知旋轉角度為逆時針方向
(2)
大拇指往下,代表Y軸為負向,得知旋轉角度為順時針方向2017年3月20日 星期一
Week04 陳18
<一>
先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/網站下載
(1)data.zip到桌面\window\data\模型.mtl
(2)window.zip到桌面\window\Transformation.exe
(3)glut32.dll到桌面\window\glut32.dll
先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/網站下載
(1)data.zip到桌面\window\data\模型.mtl
(2)window.zip到桌面\window\Transformation.exe
(3)glut32.dll到桌面\window\glut32.dll
可以跑出此畫面就代表完成!!!!
<二>
(1)開啟main.cpp程式
(2)將程式碼做點改變
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.5, 0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char **argv )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Translate Rotate Scale");
glutDisplayFunc(display);
glutMainLoop();
}
<三>讓滑鼠可以移動茶壺
#include <GL/glut.h>
float mouseX=0,mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(mouseX, mouseY, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
mouseX=(x-150)/150.0;
mouseY=-(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc,char **argv )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Translate Rotate Scale");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
<四>開口笑
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f( %.2f, %.2f);\n", (x-250)/250.0, -(y-250)/250.0 );
}
float mouth=0;
void motion(int x, int y)
{
glColor3f( 1, x/500.0 , y/500.0 );
glutPostRedisplay();
mouth = x/300.0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle< 3.1415926 *2 -mouth ; angle+= 3.1415926/100){
glVertex2f( cos(angle), sin(angle) );
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f( %.2f, %.2f);\n", (x-250)/250.0, -(y-250)/250.0 );
}
float mouth=0;
void motion(int x, int y)
{
glColor3f( 1, x/500.0 , y/500.0 );
glutPostRedisplay();
mouth = x/300.0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle< 3.1415926 *2 -mouth ; angle+= 3.1415926/100){
glVertex2f( cos(angle), sin(angle) );
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
<五>會轉的茶壺
#include <GL/glut.h>
float mouseX=0,mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScalef(mouseX,mouseY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
mouseX=(x-150)/150.0;
mouseY=-(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc,char **argv )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Translate Rotate Scale");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
<六>完成Zuvio的回答問題
2017年3月13日 星期一
Week03 陳18
(一)茶壺
1.開啟main.cpp程式
2.將程式碼做點改變
#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("04160134 Number 1");
glutDisplayFunc(display);
glutMainLoop();
}
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button,state, x, y);
}
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
(三)顏色
(四)滑鼠拖曳變色
<藍色字是多加的程式碼>
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button,state, x, y);
}
void motion(int x, int y)
{
printf("%d %d\n", x, y);
glColor3f( 1,x/500.0 , y/500.0 );
glutPostRedisplay();
}
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
2.將程式碼做點改變
#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("04160134 Number 1");
glutDisplayFunc(display);
glutMainLoop();
}
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button,state, x, y);
}
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
(三)顏色
<藍色字是多加的程式碼>
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button,state, x, y);
glColor3f( 1, x/300.0, y/300.0 );
glutPostRedisplay();
}
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
(四)滑鼠拖曳變色
<藍色字是多加的程式碼>
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button,state, x, y);
}
void motion(int x, int y)
{
printf("%d %d\n", x, y);
glColor3f( 1,x/500.0 , y/500.0 );
glutPostRedisplay();
}
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
(五)開口笑
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f( %.2f, %.2f);\n", (x-250)/250.0, -(y-250)/250.0 );
}
float mouth=0;
void motion(int x, int y)
{
glColor3f( 1, x/500.0 , y/500.0 );
glutPostRedisplay();
mouth = x/300.0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle< 3.1415926 *2 -mouth ; angle+= 3.1415926/100){
glVertex2f( cos(angle), sin(angle) );
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
#include<math.h>
#include<stdio.h>
#include <GL/glut.h>
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) printf("glVertex2f( %.2f, %.2f);\n", (x-250)/250.0, -(y-250)/250.0 );
}
float mouth=0;
void motion(int x, int y)
{
glColor3f( 1, x/500.0 , y/500.0 );
glutPostRedisplay();
mouth = x/300.0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle< 3.1415926 *2 -mouth ; angle+= 3.1415926/100){
glVertex2f( cos(angle), sin(angle) );
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("04160134 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
2017年3月6日 星期一
Week 02 陳18
1.複習上週作業


2.親手打造第一個GLUT程式
步驟:
(1)開啟CodeBlocks
(2)點選File->New->Project
(3)選GLUT project
(4)點選next->命名為學號_glut並存於桌面
(5)下載後出現壓縮檔,解壓縮於桌面並開啟lib資料夾確認是否有libglut32.a
已上是上週複習
(6)把程式碼打開並參考老師傳的截圖將程式碼整理後執行
(7)出現圖案即可截圖
3.將茶壺變色
將上面程式碼加上一行
glColor3f(1,0,0);
即可
4.找自己想要的顏色之RGB
5.三角形
訂閱:
文章 (Atom)





















































