§每周都有超連結
第1周:嘗試建立 OpenGL project、GLET project
第2周:點線面、顏色
重點程式碼:
glVertex2f(x,y); ///頂點
glColor3f(r,g,b); ///顏色
第3周:移動、旋轉、縮放
重點程式碼:新增display()、motion()
第4周:矩陣
重點程式碼:新增mouse() 、矩陣
glPushMatrix(); ///備份矩陣
glTranslated(x,y,z); ///移動
glRotated(angle,x,y,z); ///旋轉(包含角度)
glScalef(x,y,z); ///放大縮小
glBegin(GL_POLYGON); ///開始繪製(凸)多邊形
glColor3f(r,g,b); ///顏色 glVertex3f(x,y,z); ///頂點
glEnd(); ///結束繪圖
glPopMatrix(); ///還原矩陣
第5周:T_R_T
重點程式碼:
glTranslated(x,y,z); ///移動
glRotated(angle,x,y,z); ///旋轉(包含角度)
glTranslated(x,y,z); ///移動
第7周:讀OBJ檔、設定compiler
重點程式碼:
#include "glm.h"
GLMmodel* pmodel = NULL;
if (!pmodel) {
pmodel = glmReadOBJ("檔名.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
}
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
第8周:打光、陣列
重點程式碼:
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 };
glVertex2f(x,y); ///頂點
glColor3f(r,g,b); ///顏色
第3周:移動、旋轉、縮放
重點程式碼:新增display()、motion()
第4周:矩陣
重點程式碼:新增mouse() 、矩陣
glPushMatrix(); ///備份矩陣
glTranslated(x,y,z); ///移動
glRotated(angle,x,y,z); ///旋轉(包含角度)
glScalef(x,y,z); ///放大縮小
glBegin(GL_POLYGON); ///開始繪製(凸)多邊形
glColor3f(r,g,b); ///顏色 glVertex3f(x,y,z); ///頂點
glEnd(); ///結束繪圖
glPopMatrix(); ///還原矩陣
第5周:T_R_T
重點程式碼:
glTranslated(x,y,z); ///移動
glRotated(angle,x,y,z); ///旋轉(包含角度)
glTranslated(x,y,z); ///移動
第7周:讀OBJ檔、設定compiler
重點程式碼:
#include "glm.h"
GLMmodel* pmodel = NULL;
if (!pmodel) {
pmodel = glmReadOBJ("檔名.obj");
if (!pmodel) exit(0);
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
}
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
第8周:打光、陣列
重點程式碼:
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 };
glEnable(GL_LIGHT0); ///打開LIGHT0
glEnable(GL_NORMALIZE); ///打開法向量
glEnable(GL_COLOR_MATERIAL); ///打開下面的 glLight 和 glMaterial
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);
第10周:貼圖 、OpenCV
重點程式碼:
#include <opencv/highgui.h>
IplImage * img = cvLoadImage("檔名.jpg"); ///宣告指標,讀圖片
cvShowImage("week10opencv",img); ///秀圖片
cvWaitKey(0); ///必要!! 要有等待的時間畫圖
第11周:聲音、音效
重點程式碼:
#include <mmsystem.h>
(1) PlaySound("bubbs.wav",NULL,SND_ASYNC); ///不同步
(2) PlaySound("bubbs.wav",NULL,SND_SYNC); ///同步
第12周:計時器
重點程式碼:新增timer()、播放MP3
#include "CMP3_MCI.h"
CMP3_MCI mymp3;
mymp3.Load("檔名.mp3");
mymp3.Play();
第13周:讀寫檔案
第14周:攝影機、投影矩陣
沒有留言:
張貼留言