2019年3月15日 星期五

week04-2

1.下載Download freeglut 3.0.0 for MinGW

2.複製libfreeglut.a並改名為libglut32.a


3.開啟codeblocks並開啟glut project


4.將程式改為
#include <GL/glut.h>
float x=0,y=0;///現在重點在滑鼠
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣,保護好
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);///用於移動
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣,恢復
    glutSwapBuffers();
}
void motion(int nowx,int nowy)
{
    x=nowx;y=nowy;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///現在重點在滑鼠
    glutMainLoop();
}
跑程式後會出現可以用滑鼠移動的茶壺


將程式改為
#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(y,1,0,0);///y軸旋轉
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
    x=nowx;y=nowy;
    display();
}
int main( int argc , char ** argv )
{
    glutInit( &argc , argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow( "week04" );
    glutDisplayFunc( display );
    glutMotionFunc(motion);
    glutMainLoop( );
}
跑程式後會出現可以旋轉的茶壺



沒有留言:

張貼留言