Week03
下載老師給的範例
到老師的網頁 https://jsyeh.org/3dcg10/ 下載 win32 和data
解壓縮win32 和 data
將data放入window
打開 Transformation.exe
可以拉動數字會改變
如何貼出漂亮程式碼
*使用GitHub Gist
按+ 打檔名加.cpp
貼上程式碼
再將網址貼回部落格
讓茶壺移動
week03-1
點開 freeglut 的壓縮檔
拉到桌面上
把 桌面\freeglut\lib 目錄裡的 libfreeglut.a 複製成 libglut32.a
打開CodeBlocks, File-New-Project
選 GLUT專案
專案名: week03-1_GLUT
把 GLUT 的目錄, 設成 桌面的 freeglut 就可以執行
開啟GLUT
*glTranslatef(0.5, 0.5, 0);讓茶壺移動
glPopMatrix();
glPushMatrix();
#include <GL/glut.h>
void display(){
glPushMatrix();
glTranslatef(0.5, 0.5, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week03");
glutDisplayFunc(display);
glutMainLoop();
}
讓茶壺隨著滑鼠移動
week03-2
*座標減一半,除一半
#include <GL/glut.h>
float X=0, Y=0, Z=0;
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(X, Y, Z);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y){
X = (x-150)/150.0;
Y = -(y-150)/150.0;
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week03");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
回家作業
week03-3
開新檔案, 打開小畫家 用滑鼠點出圖形的座標,並複製起來
*用小畫家幫我們寫程式
#include <GL/glut.h>
void display(){
glBegin(GL_POLYGON);
glColor3f(35/255.0, 55/255.0, 114/255.0);
glVertex2f( (9-100)/100.0, -(78-100)/100.0 );
glVertex2f( (9-100)/100.0, -(160-100)/100.0 );
glVertex2f( (59-100)/100.0, -(160-100)/100.0 );
glVertex2f( (59-100)/100.0, -(78-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(84/255.0, 100/255.0, 154/255.0);
glVertex2f( (14-100)/100.0, -(96-100)/100.0 );
glVertex2f( (14-100)/100.0, -(155-100)/100.0 );
glVertex2f( (54-100)/100.0, -(155-100)/100.0 );
glVertex2f( (54-100)/100.0, -(96-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(108/255.0, 126/255.0, 172/255.0);
glVertex2f( (14-100)/100.0, -(84-100)/100.0 );
glVertex2f( (14-100)/100.0, -(96-100)/100.0 );
glVertex2f( (54-100)/100.0, -(96-100)/100.0 );
glVertex2f( (54-100)/100.0, -(84-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(35/255.0, 55/255.0, 114/255.0);
glVertex2f( (59-100)/100.0, -(87-100)/100.0 );
glVertex2f( (83-100)/100.0, -(77-100)/100.0 );
glVertex2f( (110-100)/100.0, -(23-100)/100.0 );
glVertex2f( (135-100)/100.0, -(23-100)/100.0 );
glVertex2f( (135-100)/100.0, -(40-100)/100.0 );
glVertex2f( (130-100)/100.0, -(48-100)/100.0 );
glVertex2f( (130-100)/100.0, -(72-100)/100.0 );
glVertex2f( (159-100)/100.0, -(72-100)/100.0 );
glVertex2f( (172-100)/100.0, -(80-100)/100.0 );
glVertex2f( (172-100)/100.0, -(148-100)/100.0 );
glVertex2f( (155-100)/100.0, -(162-100)/100.0 );
glVertex2f( (98-100)/100.0, -(162-100)/100.0 );
glVertex2f( (84-100)/100.0, -(151-100)/100.0 );
glVertex2f( (59-100)/100.0, -(151-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(255/255.0, 255/255.0, 255/255.0);
glVertex2f( (61-100)/100.0, -(93-100)/100.0 );
glVertex2f( (89-100)/100.0, -(80-100)/100.0 );
glVertex2f( (114-100)/100.0, -(28-100)/100.0 );
glVertex2f( (128-100)/100.0, -(28-100)/100.0 );
glVertex2f( (128-100)/100.0, -(40-100)/100.0 );
glVertex2f( (125-100)/100.0, -(48-100)/100.0 );
glVertex2f( (125-100)/100.0, -(77-100)/100.0 );
glVertex2f( (158-100)/100.0, -(77-100)/100.0 );
glVertex2f( (165-100)/100.0, -(82-100)/100.0 );
glVertex2f( (165-100)/100.0, -(146-100)/100.0 );
glVertex2f( (152-100)/100.0, -(156-100)/100.0 );
glVertex2f( (103-100)/100.0, -(156-100)/100.0 );
glVertex2f( (86-100)/100.0, -(145-100)/100.0 );
glVertex2f( (61-100)/100.0, -(146-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(223/255.0, 230/255.0, 230/255.0);
glVertex2f( (61-100)/100.0, -(133-100)/100.0 );
glVertex2f( (89-100)/100.0, -(133-100)/100.0 );
glVertex2f( (101-100)/100.0, -(142-100)/100.0 );
glVertex2f( (103-100)/100.0, -(156-100)/100.0 );
glVertex2f( (86-100)/100.0, -(146-100)/100.0 );
glVertex2f( (61-100)/100.0, -(146-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(223/255.0, 230/255.0, 230/255.0);
glVertex2f( (101-100)/100.0, -(142-100)/100.0 );
glVertex2f( (148-100)/100.0, -(142-100)/100.0 );
glVertex2f( (152-100)/100.0, -(156-100)/100.0 );
glVertex2f( (103-100)/100.0, -(156-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(223/255.0, 230/255.0, 230/255.0);
glVertex2f( (148-100)/100.0, -(142-100)/100.0 );
glVertex2f( (165-100)/100.0, -(127-100)/100.0 );
glVertex2f( (165-100)/100.0, -(146-100)/100.0 );
glVertex2f( (152-100)/100.0, -(156-100)/100.0 );
glEnd();
glBegin(GL_POLYGON);
glColor3f(223/255.0, 230/255.0, 230/255.0);
glVertex2f( (128-100)/100.0, -(28-100)/100.0 );
glVertex2f( (128-100)/100.0, -(40-100)/100.0 );
glVertex2f( (125-100)/100.0, -(48-100)/100.0 );
glVertex2f( (125-100)/100.0, -(77-100)/100.0 );
glVertex2f( (117-100)/100.0, -(74-100)/100.0 );
glVertex2f( (120-100)/100.0, -(43-100)/100.0 );
glEnd();
glutSwapBuffers();
}
int main(int argc, char * argv[] )
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week02");
glutDisplayFunc(display);
glutMainLoop();
}







沒有留言:
張貼留言