1.從上課軟體下載freeglut
2.將壓縮檔解壓到桌面
3.點開freeglut後復製其連結
4.點開lib後將freeglut.a復製
5.改名為libglut32.a (124KB)
6.到codeblock開新的專案 file > project,(當名為week03_mouse_glScalef)
7.將上週的10行程式貼到這次的(
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03_mouse");
glutDisplayFunc(display);
glutMainLoop();
}
)
8.寫兩行一個清背景一個讓背景(glClearColor(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);)變淡黃色(glClear(1.0,1.0,0.9,1.0);)
void motion(int x , int y)
{
angle = x;
display();
}
glPushMatrix();///49
///glTranslatef(teapotX,teapotY,0);
glRotated(angle ,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();///54
12.將上週的10行程式貼到這次的(
#include <GL/glut.h>
void display()
{
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03_mouse");
glutDisplayFunc(display);
glutMainLoop();
}
)
13.加上這兩行glClearColor(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glutKeyboardFunc(keyboard);
void keyboard(unsigned char key ,int x, int y)
{
printf("key: %c x: %d y: %d\n",key,x,y);
}
glutKeyboardFunc(keyboard);void mouse(int button,int state, int x,int y)
{
oldX=x;
}
void motion(int x,int y)
{
angle += (x-oldX);
oldX = x;
display();
}
glutMouseFunc(mouse);
glutMotionFunc(motion);
glPushMatrix();
glRotatef(angle ,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();(圖片沒加到這行,要補上)
17.到老師的網站(https://jsyeh.org/3dcg10/)
18.下載data,win32
19.解壓縮data.zip,window.zip
20.將data資料夾丟到window裡面(解壓後的檔案)
21.點開Transformation.exe22.到codeblock開新的專案 file > project,(當名為week04_translate_rotate_scale
23.將剛剛的程式貼到這次的(
#include <GL/glut.h>
#include <stdio.h>
float angle =0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle ,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state, int x,int y)
{
oldX=x;
}
void motion(int x,int y)
{
angle += (x-oldX);
oldX = x;
display();
}
void keyboard(unsigned char key ,int x, int y)
{
printf("key: %c x: %d y: %d\n",key,x,y);
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04_keyboard_mouse_motion");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
24.刪掉一些程式碼
25.多增加這行 glutIdleFunc(display);還有(angle++),可以讓茶壺自動轉
26.這三行讓茶壺變小且座標往右並且自轉
glTranslated(0.8,0,0);
glRotatef(angle++ ,0,0,1);
glScalef(0.3,0.3,0.3);
29.將剛剛的程式碼貼上並下面兩行交換位置
glTranslated(0.8,0,0);
glRotatef(angle++ ,0,0,1);
沒有留言:
張貼留言