2018年3月12日 星期一

Week03_+0筆記

茶壺

#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("Week03");

    glutDisplayFunc(display);
    glutMainLoop();
}
背景顏色+滑鼠資訊(座標)

#include <GL/glut.h>
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(0,1,0);
    glutSolidTeapot(0.3);

    glutSwapBuffers();
}
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
   if(state==GLUT_DOWN) printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);

}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

茶壺移動的座標加入Mouse
#include <GL/glut.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();
    glutSwapBuffers();
}
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
   if(state==GLUT_DOWN) printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);

}
void motion(int x, int y)
{
    teapotX=(x-150)/150.0; teapotY= -(y-150)/150.0;
    printf("%d %d\n", x,y);
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}



加入Motion

#include <GL/glut.h>
/*float teapotX=0,teapotY=0;*/
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   /* glPushMatrix();
        glTranslatef(teapotX,teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();*/
    glutSwapBuffers();
}
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)printf("glVertex2f(%f, %f);\n",(x-150)/150.0,-(y-150)/150.0);

}
/*void motion(int x,int y)
{
    teapotX=(x-150)/150.0;
    teapotY=-(y-150)/150.0;
    printf("%d %d\n",x,y);
    glutPostRedisplay();

}*/
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("05160133_week03 good goood!");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}








沒有留言:

張貼留言