2021年3月15日 星期一

我是鬼_week04

1.先做跟上禮拜一樣的水壺 

#include<GL/glut.h>

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSolidTeapot(0.3);

    glutSwapBuffers();

}

int main(int argc, char ** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("08160812我是鬼");

    glutDisplayFunc(display);

    glutMainLoop();

}


1.使用上禮拜的程式碼

2.改變形狀

3.加入(按下滑鼠)就產生程式碼的指令

#include<GL/glut.h>

#include<stdio.h>

void display()

{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POLYGON);

        glVertex2f((140-150)/150.0,-(114-150)/150.0);

        glVertex2f((157-150)/150.0,-(111-150)/150.0);

        glVertex2f((185-150)/150.0,-(129-150)/150.0);

        glVertex2f((210-150)/150.0,-(126-150)/150.0);

        glVertex2f((227-150)/150.0,-(129-150)/150.0);

        glVertex2f((211-150)/150.0,-(165-150)/150.0);

        glVertex2f((186-150)/150.0,-(186-150)/150.0);

        glVertex2f((124-150)/150.0,-(188-150)/150.0);

        glVertex2f((105-150)/150.0,-(176-150)/150.0);

        glVertex2f((79-150)/150.0,-(145-150)/150.0);

        glVertex2f((84-150)/150.0,-(133-150)/150.0);

        glVertex2f((114-150)/150.0,-(128-150)/150.0);

        glVertex2f((137-150)/150.0,-(116-150)/150.0);

    glEnd();

    glutSwapBuffers();

}

void mouse(int button,int state,int x,int y)

{

    if(state==GLUT_DOWN){

        printf("glVertex3f((%d-150)/150.0,-(%d-150)/150.0;\n",x,y);

    }

}

int main(int argc, char ** argv)


{


    glutInit( &argc, argv);


    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);


    glutCreateWindow("week04 mouse");


    glutDisplayFunc(display);


    glutMainLoop();


}


1.使用座標的方式來呈現水壺
#include<GL/glut.h>
#include<stdio.h>
float teapotX=0,teapotY=0;
void display()

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glEnd();
    glutSwapBuffers();

}
void motion(int x,int y)
{
    teapotX = (x-150)/150.0;
    teapotY = -(y-150)/150.;
    display();
}
int main(int argc, char ** argv)

{

    glutInit( &argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("08160812我是鬼");

    glutDisplayFunc(display);

    glutMainLoop();

}













沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...