顯示具有 02160200_黃政維 標籤的文章。 顯示所有文章
顯示具有 02160200_黃政維 標籤的文章。 顯示所有文章

2015年6月10日 星期三

week16 02160200課堂練習

程式碼
#include <GL/glut.h>
#include<stdio.h>
FILE * fout=NULL;
FILE * fin=NULL;
float angle[10]={}, oldX=0, oldY=0;
int angleID=1;
void drawBody(){
    glPushMatrix();
    glScalef(1, 0.5, 0.5);
    glutSolidCube(1);
    glPopMatrix();
}
void drawArm(){
    glPushMatrix();
    glScalef(0.6, 0.3, 0.3);
    glutSolidCube(1);
    glPopMatrix();
}
void display()
{
    { ///Lighting
    glColor3ub(166,132,100);
    GLfloat pos[]={0, 0, -1, 0};
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_LIGHT0);
    //glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }
    glPushMatrix();
        glTranslatef(0.5, 0, 0);///最後一步, 把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去 ver 4
        glRotatef(angle[1], 0,0,1);///把下面整團, 都對中間做旋轉 ver 3
        glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間 ver 2
        drawArm();///這是個Arm ver 1  Right Upper Arm
        glPushMatrix();
            glTranslatef(0.25, 0, 0);///最後一步, 把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去 ver 4
            glRotatef(angle[2], 0,0,1);///把下面整團, 都對中間做旋轉 ver 3
            glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間 ver 2
            drawArm(); ///Right Lower Arm
        glPopMatrix();
    glPopMatrix();
    glPushMatrix();
        glTranslatef(-0.5, 0, 0);///最後一步, 把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去 ver 4
        glRotatef(-angle[3], 0,0,1);///把下面整團, 都對中間做旋轉 ver 3
        glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間 ver 2
        drawArm();///這是個Arm ver 1  Left Upper Arm
        glPushMatrix();
            glTranslatef(-0.25, 0, 0);///最後一步, 把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去 ver 4
            glRotatef(-angle[4], 0,0,1);///把下面整團, 都對中間做旋轉 ver 3
            glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間 ver 2
            drawArm(); ///Left Lower Arm
        glPopMatrix();
    glPopMatrix();
    drawBody();
    glFlush();
}
void motion(int x, int y)
{   angle[angleID] -= y - oldY;
    oldY=y; oldX=x;

    if(fout==NULL) fout=fopen("a.txt","w+");
    for(int i=0;i<5;i++)
    {
        printf(   "%f ",angle[i]);
        fprintf(fout,"%f ",angle[i]);
    }
    printf("\n");
    fprintf(fout,"\n");
}
void mouse(int button, int state, int x, int y){
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void timer(int t)
{
    glutTimerFunc(500, timer, t+1);
    if(fin==NULL)fopen("a.txt","r");
    for(int i=0;i<5;i++)
    {
         fscanf(fin,"%f",&angle[i]);
        printf("%f ",angle[i]);
    }
    glutPostRedisplay();
}
void keyboard(unsigned char key,int x,int y)
{
    if(key=='1')angleID=1;
    if(key=='2')angleID=2;
    if(key=='3')angleID=3;
    if(key=='4')angleID=4;
    if(key=='p')glutTimerFunc(10,timer,0);
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("T-R-T test");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


2015年6月3日 星期三

week15 02160200黃政維課堂練習

TODO:如何把T-R-T參數調出來
程式碼:
#include <GL/glut.h>
#include <stdio.h>
float x1=-0.4, y1=0, x2=0, y2=0, angle=0;
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(x1, y1, 0);//要掛在哪裡?
        glRotatef(angle, 0,0,1);
        glTranslatef(-0.25, -0.11, 0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.2);
    glPopMatrix();
    glPushMatrix();
        glTranslatef(x2, y2, 0);
        glColor3f(1,0,0);
        glutSolidTeapot(0.2);
    glPopMatrix();
    glFlush();///先不用 glutSwapBuffers(); 配合 glutInitDisplayMode(GLUT_DOUBLE);
}
void keyboard(unsigned char key, int x, int y)
{
    if(key=='1') x1+=0.1;
    if(key=='2') x1-=0.1;
    if(key=='3') y1+=0.1;
    if(key=='4') y1-=0.1;
    if(key=='5') angle+=10;
    if(key=='6') angle-=10;
    printf("%f %f\n", x1, y1);
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("Robot3D");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
}


2015年5月27日 星期三

week14 02160200課堂作業

todo畫茶壺
todoTRT
程式碼
#include <GL/glut.h>
float angle=0;
void display()
{
    GLfloat pos []={0,0,-1,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0.6,0.2,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.3,0,0);///把柄當中心
        glutSolidTeapot(0.3);
    glPopMatrix();
     glutSolidTeapot(0.3);
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20,timer,t+1);
    angle++;
    glutPostRedisplay();
}
int main(int argc ,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("T-R-T test");
    glutDisplayFunc(display);
    glutTimerFunc(20,timer,0);

    glutMainLoop();
}


2015年5月20日 星期三

week13 02160200 課堂練習

TODO:垂直投影

程式碼
#include <GL/glut.h>

void display()
{
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glFlush();
}

void reshape(int w,int h)
{
     glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-w/2,w/2,-h/2,h/2,-1000,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);



    glutMainLoop();
}
攝影機.運鏡
程式碼


#include <GL/glut.h>
float eyeX=-100,eyeY=80,eye2=-200;

void display()
{
    GLfloat pos[]={0,0,200,0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        gluLookAt(eyeX,eyeY,eye2,0,0,0,0,1,0);
    glPushMatrix();
        glutSolidTeapot(100);
    glPopMatrix();
    glPopMatrix();
    glFlush();
}
void motion(int x,int y)
{
    eyeX=x-400;eyeY=300-y;
    glutPostRedisplay();
}

void reshape(int w,int h)
{
     glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90,w/h,0.001,10000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
void timer(int t )
{
    glutTimerFunc(20,timer,t+1);
    eyeX+=2;
    if(eyeX>300)eyeY+=4;
    glutPostRedisplay();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitWindowSize(800,600);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutTimerFunc(0,timer,0);



    glutMainLoop();
}



2015年5月13日 星期三

week12 02160200 課堂練習

Todo:今天glm.c有6行
讀入3D模型

程式碼

#include "glm.h"///我們要用glm.h和glm.c(要先COPY同目幕)
GLMmodel * pmodel = NULL;

void display()
{
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glFlush();
}

int main(int argc, char**argv)
{
    pmodel = glmReadOBJ("porsche.obj");///如果沒檔案\找不到就會當機
    glmUnitize(pmodel);
    glmFacetNormals(pmodel);
    glmVertexNormals(pmodel,90.0);

    glutInit(&argc, argv);
    glutCreateWindow("GLUT");
    glutDisplayFunc(display);
    glutMainLoop();
}


打光車車
程式碼

#include "glm.h"///我們要用glm.h和glm.c(要先COPY同目墓)
GLMmodel * pmodel = NULL;

void display()
{
    GLfloat pos[] ={0.0,0.0,-1.0,0.0};
    glLightfv(GL_LIGHT0,GL_POSITION,pos);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
    glFlush();
}

int main(int argc, char**argv)
{
    pmodel = glmReadOBJ("porsche.obj");///如果沒檔案\找不到就會當機
    glmUnitize(pmodel);
    glmFacetNormals(pmodel);
    glmVertexNormals(pmodel,90.0);

    glutInit(&argc, argv);
    glutCreateWindow("GLUT");
    glutDisplayFunc(display);
    glutMainLoop();
}



2015年5月6日 星期三

week11 課堂練習02160200

Timer計時器(等速)

TODO:下載freeglut
TODO:下載OpenCV2.1(安裝)
TODO:下載會動的地球
TODO上周Project設定
            目錄(a)compiler的include
                     (b)Linker的Lib
                     (c)Link參數
TODO:
            (1)glutTimerFunce(2000,timer,0)
           (2)void timer (int t)
                                      {
glutTimerFunc(20, timer, 0);
    glutPostRedisplay();
                                       }
程式碼

#include <opencv/highgui.h> ///for cvLoadImage()
#include <opencv/cv.h> ///for cvCvtColor()
#include <GL/glut.h> ///3D glut
#include <stdio.h>
float angle=0; ///自動轉很帥
GLUquadric * quad;
void display()
{   glEnable(GL_DEPTH_TEST); ///要啟動 Detph Test 深度值的測試,3D顯示才正確
    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///自動轉很帥
        glRotatef(90, 1,0,0);
        glRotatef(angle, 0,0,1);///自動轉很帥
        gluQuadricTexture(quad, 1);
        gluSphere(quad, 0.5, 30, 30); ///glutSolidTeapot(0.3);
    glPopMatrix();///自動轉很帥
    glFlush();
    angle+=1;///自動轉很帥
}
void myInit()
{
    quad = gluNewQuadric();
    IplImage * img = cvLoadImage("image.jpg"); ///OpenCV讀圖
    cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
    glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
    GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
    glGenTextures(1, &id); /// 產生Generate 貼圖ID
    glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
}   ///最後一行最難/最重要, 所貼圖影像的資料都設定好
void timer(int t)
{/// 1000 msec   50fps:20msec
    glutTimerFunc(20, timer, 0);
    //printf("timer now\n");
    glutPostRedisplay();
}
int main(int argc, char**argv)
{   glutInit(&argc, argv);
    glutCreateWindow("3D");
    glutDisplayFunc(display); ///顯示
    //glutIdleFunc(display);///自動轉很帥 (閒閒沒事幹, 就重畫)
    glutTimerFunc(2000, timer, 0);

    myInit(); ///我的 init 初始化 把貼圖準備好 前面OpenCV 2行, 後面 OpenGL 9行
    glutMainLoop();
}



2015年4月29日 星期三

week10 02160200 2D 3D圖

TODO:下載OpenCV2.1 安裝C:\Cpen2.1
TODO:設定OpenCV
              (1)file-new-Project
              (2)project-Bluid設定



程式碼
#include <opencv/highgui.h>
#include<GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glFlush();
    angle+=0.1;
}
int main(int argc,char**argv)
{
    IplImage *img=cvLoadImage("image.jpg");
    cvNamedWindow("2D");
    cvShowImage("2D",img);
    cvWaitKey(1);

    glutInit(&argc,argv);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMainLoop();
}
程式碼
#include <opencv/highgui.h> ///for cvLoadImage()
#include <opencv/cv.h> ///for cvCvtColor()
#include <GL/glut.h> ///3D glut
float angle=0; ///自動轉很帥
void display()
{   glEnable(GL_DEPTH_TEST); ///要啟動 Detph Test 深度值的測試,3D顯示才正確
    glClear(GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///自動轉很帥
        glRotatef(angle, 0,1,0);///自動轉很帥
        glutSolidTeapot(0.3);
    glPopMatrix();///自動轉很帥
    glFlush();
    angle+=0.1;///自動轉很帥
}
void myInit()
{   IplImage * img = cvLoadImage("image.jpg"); ///OpenCV讀圖
    cvCvtColor(img,img, CV_BGR2RGB); ///OpenCV轉色彩 (需要cv.h)
    glEnable(GL_TEXTURE_2D); ///1. 開啟貼圖功能
    GLuint id; ///準備一個 unsigned int 整數, 叫 貼圖ID
    glGenTextures(1, &id); /// 產生Generate 貼圖ID
    glBindTexture(GL_TEXTURE_2D, id); ///綁定bind 貼圖ID
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖T, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); /// 貼圖參數, 超過包裝的範圖S, 就重覆貼圖
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /// 貼圖參數, 放大時的內插, 用最近點
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /// 貼圖參數, 縮小時的內插, 用最近點
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
}   ///最後一行最難/最重要, 所有貼圖影像的資料都設定好
int main(int argc, char**argv)
{   glutInit(&argc, argv);
    glutCreateWindow("3D");
    glutDisplayFunc(display); ///顯示
    glutIdleFunc(display);///自動轉很帥 (閒閒沒事幹, 就重畫)
    myInit(); ///我的 init 初始化 把貼圖準備好 前面OpenCV 2行, 後面 OpenGL 9行
    glutMainLoop();
}




會轉的茶壺

程式碼


#include <GL/glut.h>
float angle=0;
void timer(int t)
{
    glutTimerFunc(10, timer, t+1);
    angle+=1;
    glutPostRedisplay();
}
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
     glRotatef(angle, 0,1,0);
     glutSolidTeapot(0.5);
    glPopMatrix();
    glFlush();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("3D");
    glutDisplayFunc(display);
    glutTimerFunc(10, timer, 0);
    glutMainLoop();
}




2015年4月15日 星期三

week08 02160200 小遊戲

TODO:freeglut
TODO:glut專案
            glutFullScreen();
TODO:試跑NeHe Lesson32
程式碼:
             #include<stdio.h>
#include<GL/glut.h>
#include<mmsystem.h>
float potX=-1,potY=0;
void display()
{
    glClearColor(0.5,0.5,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(potX,potY,0);
        glutSolidTeapot(0.05);
    glPopMatrix();

    glFlush();
    potX+=0.01;
    if(potX>1.1)potX=-1.1;
}
void keyboard(unsigned char key,int x,int y)
{
    exit(0);
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
    {
        PlaySound("shot.wav",NULL,SND_ASYNC);
        printf("SHOT!!!\n");
        float mouseX=2*x/1280.0-1,mouseY=-(2*y/1024.0-1);
        if(abs(mouseX-potX)<0.01&&abs(mouseY-potY)<0.01)
        {
            printf("YA! Got it!\n");
            PlaySound("chaha.wav",NULL,SND_ASYNC);

        }
    }
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");
    glutFullScreen();///全螢幕
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);

    glutMainLoop();
}


2015年4月8日 星期三

week07 02160200 Mouse.Keyboard.UI.音樂

程式碼
#include<GL/glut.h>
#include <mmsystem.h>///播音樂
#include<stdio.h>
void display()
{

    glutSolidTeapot(0.3);
    glFlush();
}
void keyboard(unsigned char key,int x, int y)///按鍵盤會print東西
{
    if(key=='a'||key=='A')
    {
        printf("AAA\n");
    }
    else if(key=='b')
    {
        printf("BBB\n");
    }
}
void mouse(int button,int state,int x,int y)///聲音要放freeglut的bin裡
{
    printf("now playing sound");
    PlaySound("madmoo.wav",NULL,SND_ASYNC);
}
int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);///call mouse
    glutMainLoop();
}


2015年3月25日 星期三

week05 02160200 自己3D模型 MOUSE轉動

TODO:先畫號3D方塊
TODO: 畫面自動轉    glutIdleFunc(display)
TODO:用glBegin(GL_POLYGON);及glBegin(GL_QUAD_STRIP);畫長條形
TODO:glutMotionFunc(motion);///mouse的motion來轉動


程式碼
#include <GL/glut.h>

float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
                glPushMatrix();///備份Matrix
                glRotatef(angle,0,1,0.5);///旋轉
glBegin(GL_POLYGON);///正方形
    glColor3f(1,1,0);///(r,g,b)
    glVertex3f(0.1,0.1,0.8);///頂點
    glVertex3f(-0.1,0.1,0.8);
    glVertex3f(-0.1,-0.1,0.8);
    glVertex3f(0.1,-0.1,0.8);
glEnd();
glBegin(GL_POLYGON);///正方形
    glColor3f(1,0,0);
    glVertex3f(0.1,0.1,-0.8);
    glVertex3f(-0.1,0.1,-0.8);
    glVertex3f(-0.1,-0.1,-0.8);
    glVertex3f(0.1,-0.1,-0.8);
glEnd();
glBegin(GL_QUAD_STRIP);///長條型
    glVertex3f(0.1,0.1,0.8);
     glVertex3f(0.1,0.1,-0.8);
    glVertex3f(-0.1,0.1,0.8);
     glVertex3f(-0.1,0.1,-0.8);
    glVertex3f(-0.1,-0.1,0.8);
    glVertex3f(-0.1,-0.1,-0.8);
    glVertex3f(0.1,-0.1,0.8);
    glVertex3f(0.1,-0.1,-0.8);
glEnd();
                glPopMatrix();///還原Matrix
                angle+=0.01;
glFlush();
}
int oldX=0;
void motion(int x,int y)
{
    angle+=(x-oldX);
    oldX=x;
}
int main(int argc,char **argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
                glutIdleFunc(display);
    glutDisplayFunc(display);

    glutMotionFunc(motion);///mouse motion drag動作移動距離的函式
    glutMainLoop();
}

2015年3月18日 星期三

week04 02160200 3D物件 移動 旋轉

原本

#include <GL/glut.h>
void display()
{
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
    glutSolidTeapot(0.2);
    glFlush();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);

    glutMainLoop();
}


移動

#include <GL/glut.h>
void display()
{
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
    glPushMatrix();
        glTranslatef(0.5,0,0);///移動(x,y,z)
    glutSolidTeapot(0.2);
   glPopMatrix();
    glFlush();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);

    glutMainLoop();
}

旋轉

#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);///清畫面
    glPushMatrix();///備份matrix
        glRotatef(angle,1,1,0);///旋轉對(1,1,0)軸 轉動angle
    glutWireTorus(0.3,0.7,30,30);///(內徑R,外徑R,橫切,縱切)
        ///glTranslatef(0.5,0,0);移動(x,y,z)
    glutSolidTeapot(0.2);
   glPopMatrix();///還原matrix
    glFlush();
    angle+=0.1;///每次加一點

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);
    glutIdleFunc(display);

    glutMainLoop();
}


2015年3月11日 星期三

week03 02160200課堂作業改變顏色

1.彩色茶壺
程式碼
#include <GL/glut.h>
void display()
{
    glClearColor(0,0,1,1);///設定清畫面的顏色
    glClear(GL_COLOR_BUFFER_BIT);///CLEAR清畫面
    glColor3f(1,1,0);///顏色
    glutSolidTeapot(0.5);
     glColor3f(1,0,0);///顏色
    glutSolidTeapot(0.4);
     glColor3f(1,0,1);///顏色
    glutSolidTeapot(0.3);
    glFlush();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);
    glutMainLoop();
}



2.
程式碼
include <GL/glut.h>
void display()
{
    glClearColor(0,0,0.3,1);///設定清畫面的顏色
    glClear(GL_COLOR_BUFFER_BIT);///CLEAR清畫面
    glColor3f(1,1,0);///顏色

     glBegin(GL_POLYGON);
     glColor3f(1,0,0);///顏色
     glVertex2f(-1.0,-1.0);

     glColor3f(0,1,0);///顏色
     glVertex2f(1.0,0.0);

     glColor3f(0,0,1);///顏色
     glVertex2f(0.0,1.0);
   glEnd();

    glFlush();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);


    glutCreateWindow("02160200");

    glutDisplayFunc(display);
    glutMainLoop();
}
3.
程式碼
#include <GL/glut.h>
void display()
{
    glClearColor(0,0,0.3,1);///設定清畫面的顏色
    glClear(GL_COLOR_BUFFER_BIT);///CLEAR清畫面
    glColor3f(1,1,0);///顏色

     glBegin(GL_POLYGON);
     glColor3f(0.39,0.75,0.84);///顏色
     glVertex2f(0.6,0.3);
     glVertex2f(1.0,0.3);
     glVertex2f(0.2,0.15);
     glVertex2f(0.9,0.84);
   glEnd();

    glFlush();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutCreateWindow("02160200");
    glutDisplayFunc(display);
    glutMainLoop();
}


2015年3月4日 星期三

Week02 02160200黃政維課堂作業

Teapot開啟

#include <GL/glut.h>


 void display()
{
    glutSolidTeapot(0.3);
    glFlush();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);


    glutCreateWindow("02160200");

    glutDisplayFunc(display);
    glutMainLoop();


}






0行程式



GLUT 0行程式