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();
}
10.執行
13.新增新專案week04_keyboard_mouse_motion
14.新增程式碼
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
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);
glutMainLoop();
}
14.執行
15.新增程式碼
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
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();
}
16.修改程式碼
#include <GL/glut.h>
#include <stdio.h>
float angle =0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(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();
}
17.執行程式
18.進入老師的網站下載課本範例
21.新增專案week04_translate_rotate_scale
22.修改程式碼
#include <GL/glut.h>
#include <stdio.h>
float angle =0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.8, 0, 0);
glRotatef(angle++, 0, 0, 1);
glScalef(0.3,0.3,0.3);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04_keyboard_mouse_motion");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
23.執行
24.修改程式碼
#include <GL/glut.h>
#include <stdio.h>
float angle =0, oldX=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.8, 0, 0);
glRotatef(angle++, 0, 0, 1);
glScalef(0.3,0.3,0.3);
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04_translate_rotate_scale");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
25.執行
26.新增專案
27.修改程式碼
#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);
glTranslatef(0.8, 0, 0);
glScalef(0.3,0.3,0.3);
glColor3f(0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char*argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04_translate_rotate_scale");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
26.執行
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
沒有留言:
張貼留言