●互評班上同學上次功課最佳作品3名上傳moodle
●畫正圓形
#include <GL/glut.h>
#include <math.h>
void display(void)
{
glBegin(GL_POLYGON);
for(float angle=0; angle <= 3.1415926 *2; angle += 0.01)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMainLoop();
return EXIT_SUCCESS;
}
●點擊圓球變色,加上Mouse函數
圓球經過點擊之後會改變顏色,從珊瑚橘改成粉紅色
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);
}
●拖曳圓形改變顏色-加Motion函式
滑鼠拖曳到圓形不同位子時就會改變顏色
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
void display()
{
glBegin(GL_POLYGON);
for(float angle=0; angle <= 3.1415926 *2; angle += 0.01)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion (int x,int y)
{
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
#include <math.h>
#include <stdio.h>
void display()
{
glBegin(GL_POLYGON);
for(float angle=0; angle <= 3.1415926 *2; angle += 0.01)
{
glVertex2f(cos(angle),sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion (int x,int y)
{
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
return EXIT_SUCCESS;
}
●小精靈
}
●小精靈
#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_TRIANGLE_FAN);
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 motion (int x,int y)
{
mouth=x/300.0;
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
#include <math.h>
#include <stdio.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
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 motion (int x,int y)
{
mouth=x/300.0;
glColor3f(1,x/300.0,y/300.0);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
return EXIT_SUCCESS;
}
}
沒有留言:
張貼留言