2016年3月8日 星期二

Week03 林庭亘

Week 03

Shapes程式試用










點線面色彩的程式



#include <Gl/glut.h>
void display()
{
    glBegin(GL_POLYGON);
        glColor3f(1, 1, 0);
        glVertex3f(0.0, 0.0, 0.0);
        glVertex3f(1.0, 0.0, 0.0);
        glVertex3f(1.0, 1.0, 0.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMainLoop();
}

點線面色彩的程式應用



#include <Gl/glut.h>
void display()
{
    glBegin(GL_POLYGON);
        glColor3f(1, 0, 0);  glVertex3f(0.0, 0.0, 0.0);
        glColor3f(0, 1, 0);  glVertex3f(1.0, 0.0, 0.0);
        glColor3f(0, 0, 1);  glVertex3f(1.0, 1.0, 0.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMainLoop();
}

增加背景顏色



#include <Gl/glut.h>
void display()
{
    glClearColor(0.5, 0.5, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glColor3f(1, 0, 0);  glVertex3f(-1.0, 0.0, 0.0);
        glColor3f(0, 1, 0);  glVertex3f( 1.0,-1.0, 0.0);
        glColor3f(0, 0, 1);  glVertex3f( 1.0, 1.0, 0.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMainLoop();
}

點線面色彩的程式應用(多邊形)



#include <Gl/glut.h>
void display()
{
    glClearColor(0.5, 0.5, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glColor3ub(192, 215, 107);
        glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
        glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
        glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
        glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMainLoop();
}

滑鼠點擊座標



#include <Gl/glut.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN)
        printf("glVertex3f((%d-150)/150.0 -(%d-100/100.0, 0.0:\n", x, y);
}
void display()
{
    glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glColor3ub(192, 215, 107);
        glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
        glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
        glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
        glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
     
    glEnd();
    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}


多個多邊形




#include <Gl/glut.h>
#include <stdio.h>
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN)
        printf("glVertex3f((%d-150)/150.0 -(%d-150)/150.0, 0.0);\n", x, y);
}
void display()
{
    glClearColor(144/255.0, 168/255.0, 56/255.0, 1);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glColor3ub(192, 215, 107);
        glVertex3f((95-100)/100.0,-(49-100)/100.0, 0.0);
        glVertex3f((17-100)/100.0,-(106-100)/100.0, 0.0);
        glVertex3f((93-100)/100.0,-(165-100)/100.0, 0.0);
        glVertex3f((174-100)/100.0,-(103-100)/100.0, 0.0);
    glEnd();
    glBegin(GL_POLYGON);
    glVertex3f((271-150)/150.0, -(25-150)/150.0, 0.0);
    glVertex3f((204-150)/150.0, -(18-150)/150.0, 0.0);
    glVertex3f((213-150)/150.0, -(72-150)/150.0, 0.0);
    glVertex3f((273-150)/150.0, -(88-150)/150.0, 0.0);
    glEnd();

    glutSwapBuffers();
}
int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}












沒有留言:

張貼留言