一、作業互評
將hw2.zip解開後打開list.html來瀏覽同學們的作業
ctrl+可以放大 ctrl-可以縮小
並挑出認為做最好的三個作品上傳至moodle
二、練習畫正圓形
glVertex2f(cos(angle),sin(angle));
三、加上Mouse函式
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(); //post 貼個便利貼,告訴電腦有空的時候re-display
}
{
printf("%d %d %d %d\n",button,state,x,y);//印出值
glColor3f(1,x/300.0,y/300.0);//改變顏色
glutPostRedisplay(); //post 貼個便利貼,告訴電腦有空的時候re-display
}
如果執行的時候小黑窗有出現fghGenBuffers is NULL表示電腦顯示卡有問題
四、 加Motion函式拖曳Drag動起來+變色
程式碼:
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(0,0);
for(float angle=0+mouth;angle<=3.1415926 *2-mouth;angle +=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(0,0);
for(float angle=0+mouth;angle<=3.1415926 *2-mouth;angle +=3.1415926/100)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
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();
}
{
//printf("%d %d %d %d\n",button,state,x,y);//印出值
//glColor3f(1,x/300.0,y/300.0);//改變顏色
//glutPostRedisplay();
}
void motion(int x,int y)
{
mouth = x/300.0;
glColor3f(1,x/300.0,y/300.0);//改變顏色
glutPostRedisplay(); //post 貼個便利貼,告訴電腦有空的時候re-display
}
{
mouth = x/300.0;
glColor3f(1,x/300.0,y/300.0);//改變顏色
glutPostRedisplay(); //post 貼個便利貼,告訴電腦有空的時候re-display
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160241 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);//要使用滑鼠函式
glutMotionFunc(motion);
glutMainLoop();
}
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160241 Number 1");
glutDisplayFunc(display);
glutMouseFunc(mouse);//要使用滑鼠函式
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言