1:解壓縮freeglut檔案
2:用CodeBlocks建新Project
3:將freeglut.dll丟到Project資料夾中

4:打程式
#include <GL/glut.h>
void display()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("ROBOT");
glutDisplayFunc(display);
glutMainLoop();
}

作業2:
1:將作業1中的程式修改,
讓茶壺可以自轉、公轉
#include <GL/glut.h>
float rotX=0;
void display()
{
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glRotated(rotX, 0,0,1);//讓中間的茶壺變成公轉的中心點
glTranslatef(0.5,0,0);
glRotated(rotX, 0,0,1);//自轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
glutPostRedisplay();//glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("ROBOT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言