顯示具有 00163106_李士昌 標籤的文章。 顯示所有文章
顯示具有 00163106_李士昌 標籤的文章。 顯示所有文章

2014年5月29日 星期四

week15

#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
//#include "CMP3_MCI.h"
//CMP3_MCI myMP3;
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
//float angle1=0, angle2=0, angle3=0, angle4=0;
float a=0;
float angle[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
float angleOld[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
float angleNew[20]={90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
int angleID=0;
int oldX,oldY;

void timer(int t);
FILE * fout = NULL, *fin = NULL;
int i;
void mouse(int botton, int state, int x, int y)
{
oldX=x;
oldY=y;
}
void motion(int x, int y)
{
angle[angleID]+= x-oldX; oldX=x;
glutPostRedisplay();
}

void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
    cvCvtColor(img[i], img[i], CV_BGR2RGB);
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &id[i]);
    glBindTexture(GL_TEXTURE_2D, id[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
    img[0]=cvLoadImage("imgbody.png");
    img[1]=cvLoadImage("imgHand1.png");
    img[2]=cvLoadImage("imgLeg1.png");
    for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
        myPrepareTexture(i);
    }
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
    glPushMatrix();
        glScalef(0.3, 0.8, 0.8);
        glBindTexture(GL_TEXTURE_2D, id[num]);
        glBegin(GL_POLYGON);
            glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
            glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);
            glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);
            glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);
        glEnd();
    glPopMatrix();
}
void myBody(){
    glPushMatrix();
        glScalef(0.7, 0.7, 0.7);
        myPolygon(0);
    glPopMatrix();
}
void myLeg(){
    glPushMatrix();
        glScalef(0.5, 0.5, 0.5);
        myPolygon(1);
    glPopMatrix();
}
void myHand(){
    glPushMatrix();
        glScalef(0.5, 0.5, 0.5);
        myPolygon(2);
    glPopMatrix();
}
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        myBody();
        glPushMatrix();
glTranslatef(0.1,0.1,0);//右手
glRotatef(angle[1], 0,0,1);
glutWireSphere(0.05,20,20);
glTranslatef(0, -0.2, 0);
myHand();
glPushMatrix();
glTranslatef(0,-0.2,0);//右手1
glRotatef(angle[2], 0,0,1);
glutWireSphere(0.05,20,20);
glTranslatef(0, -0.2, 0);
myHand();
        glPopMatrix();
        glPopMatrix();
        glPushMatrix();
       glTranslatef(-0.1,0.1,0);//左手
       glRotatef(-angle[3], 0,0,1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myHand();
       glPushMatrix();
       glTranslatef(0,-0.2,0);//左手1
       glRotatef(-angle[4], 0,0,1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myHand();
       glPopMatrix();
        glPopMatrix();
        glPushMatrix();
       glTranslatef(-0.1,-0.2,0);//左腿
       glRotatef(-angle[5], 0,0,1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
       glPushMatrix();
       glTranslatef(0,-0.2,0);//左腿1
       glRotatef(-angle[6], 0,0,1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
       glPopMatrix();
        glPopMatrix();
        glPushMatrix();
       glTranslatef(0.1,-0.2,0);//右腿
       glRotatef(-angle[7], 0,0,-1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
       glPushMatrix();
       glTranslatef(0,-0.2,0);//右腿1
       glRotatef(-angle[8], 0,0,-1);
       glutWireSphere(0.05,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
       glPopMatrix();
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
void readNext()
{
    if(fin == NULL)fin=fopen("my_output.txt", "r");
    a += 0.1;
    for(int i=0;i<20;i++) angle[i] = angleOld[i]*(1-a) + angleNew[i]*a;
    if(a>=1)
{
a=0;
for(int i=0;i<20;i++)
{
angleOld[i] = angleNew[i];
fscanf(fin, "%f ",&angleNew[i]);
}
}
}

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=='5') angleID=5;
    if(key=='6') angleID=6;
    if(key=='7') angleID=7;
    if(key=='8') angleID=8;
   
    if(key=='s')
    {
        if(fout == NULL) fout = fopen("my_output.txt", "w+");
        for(int i=0;i<20;i++)
{
fprintf(fout, "%f ", angle[i]);
}
fprintf(fout,"\n");
    }
    if(key == 'r')
    {
readNext();
        glutPostRedisplay();
    }
    if(key == 'p')
    {
        glutTimerFunc(0, timer, 0);
    }

}
void timer(int t)
{
    glutTimerFunc(100, timer, 0);
    readNext();
    glutPostRedisplay();
}
int main()
{
   /* myMP3.Load("abc.mp3");
    myMP3.Play();*/
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
    glutCreateWindow("week15");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    myTexture();//不要忘了加哦!
    glutMainLoop();
}

2014年5月22日 星期四

week14


#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
//float angle1=0, angle2=0, angle3=0, angle4=0;
float angle[10]={0,0,0,0,0,0,0,0,0,0};
int angleID=1;
int oldX,oldY;
void mouse(int botton, int state, int x, int y)
{
oldX=x;
oldY=y;
}
void motion(int x, int y)
{
angle[angleID]+= x-oldX; oldX=x;
glutPostRedisplay();
}

void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
    cvCvtColor(img[i], img[i], CV_BGR2RGB);
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &id[i]);
    glBindTexture(GL_TEXTURE_2D, id[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
    img[0]=cvLoadImage("imgbody.png");
    img[1]=cvLoadImage("imgHand1.png");
    img[2]=cvLoadImage("imgLeg1.png");
    for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
        myPrepareTexture(i);
    }
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
    glPushMatrix();
        glScalef(0.3, 0.8, 0.8);
        glBindTexture(GL_TEXTURE_2D, id[num]);
        glBegin(GL_POLYGON);
            glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
            glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);
            glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);
            glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);
        glEnd();
    glPopMatrix();
}
void myBody(){
glPushMatrix();
glScalef(0.7, 0.7, 0.7);
myPolygon(0);
glPopMatrix();
}
void myLeg(){
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
myPolygon(1);
glPopMatrix();
}
void myHand(){
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
myPolygon(2);
glPopMatrix();
}
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        myBody();
     glPushMatrix();
         glTranslatef(0.1,0.1,0);//右手
         glRotatef(angle[1], 0,0,1);
      glutWireSphere(0.05,20,20);
         glTranslatef(0, -0.2, 0);
         myHand();
      glPushMatrix();
          glTranslatef(0,-0.2,0);//右手1
          glRotatef(angle[2], 0,0,1);
          glutWireSphere(0.05,20,20);
          glTranslatef(0, -0.2, 0);
          myHand();
     glPopMatrix();
     glPopMatrix();
     glPushMatrix();
         glTranslatef(-0.1,0.1,0);//左手
         glRotatef(-angle[3], 0,0,1);
      glutWireSphere(0.05,20,20);
         glTranslatef(0, -0.2, 0);
         myHand();
      glPushMatrix();
          glTranslatef(0,-0.2,0);//左手1
          glRotatef(-angle[4], 0,0,1);
       glutWireSphere(0.05,20,20);
          glTranslatef(0, -0.2, 0);
          myHand();
      glPopMatrix();
     glPopMatrix();
     glPushMatrix();
         glTranslatef(-0.1,-0.2,0);//左腿
         glRotatef(-angle[5], 0,0,1);
      glutWireSphere(0.05,20,20);
         glTranslatef(0, -0.2, 0);
         myLeg();
      glPushMatrix();
          glTranslatef(0,-0.2,0);//左腿1
          glRotatef(-angle[6], 0,0,1);
        glutWireSphere(0.05,20,20);
          glTranslatef(0, -0.2, 0);
       myLeg();
      glPopMatrix();
     glPopMatrix();
     glPushMatrix();
         glTranslatef(0.1,-0.2,0);//右腿
         glRotatef(-angle[7], 0,0,-1);
      glutWireSphere(0.05,20,20);
         glTranslatef(0, -0.2, 0);
         myLeg();
         glPushMatrix();
          glTranslatef(0,-0.2,0);//右腿1
          glRotatef(-angle[8], 0,0,-1);
       glutWireSphere(0.05,20,20);
          glTranslatef(0, -0.2, 0);
          myLeg();
      glPopMatrix();
     glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
void timer(int t);
FILE * fout = NULL, *fin = NULL;
int i;
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=='5') angleID=5;
if(key=='6') angleID=6;
if(key=='7') angleID=7;
if(key=='8') angleID=8;
if(key=='s')
{
if(fout == NULL) fout = fopen("my_output.txt", "w+");
fprintf(fout, "%f %f %f %f %f %f %f %f \n", angle[0], angle[1] ,angle[2] ,angle[3] ,angle[4] ,angle[5] ,angle[6] ,angle[7]);
}
if(key == 'r')
{
if(fin == NULL)fin=fopen("my_output.txt", "r");
fscanf(fin, "%f %f %f %f %f %f %f %f \n", &angle[0], &angle[1] ,&angle[2] ,&angle[3] ,&angle[4], &angle[5] ,&angle[6] ,&angle[7]);
printf("%f %f %f %f %f %f %f %f \n", angle[0], angle[1] ,angle[2] ,angle[3] ,angle[4], angle[5] ,angle[6] ,angle[7]);
}
if(key == 'p')
{
if(fin == NULL)fin=fopen("my_output.txt", "r");
glutTimerFunc(1000, timer, 0);
}
glutPostRedisplay();

}

void timer(int t)
{
glutTimerFunc(1000, timer, 0);
fscanf(fin, "%f %f %f %f %f %f %f %f \n", &angle[0], &angle[1] ,&angle[2] ,&angle[3] ,&angle[4], &angle[5] ,&angle[6] ,&angle[7]);
printf("%f %f %f %f %f %f %f %f \n", angle[0], angle[1] ,angle[2] ,angle[3] ,angle[4], angle[5] ,angle[6] ,angle[7]);
glutPostRedisplay();
}
int main()
{
myMP3.Load("abc.mp3");
myMP3.Play();
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
myTexture();//不要忘了加哦!
glutMainLoop();
}

2014年5月15日 星期四

week13



#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <stdio.h>
//IplImage *img1, *img2, *img3, *img4;
//GLuint id1, id2, id3, id4;
IplImage * img[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
GLuint id[40];//技巧1: 可以把重覆的東西, 用陣列來簡化
//float angle1=0, angle2=0, angle3=0, angle4=0;
float angle[10]={0,0,0,0,0,0,0,0,0,0};
int angleID=1;
int oldX,oldY;
void mouse(int botton, int state, int x, int y)
{
oldX=x;
oldY=y;
}
void motion(int x, int y)
{
angle[angleID]+= x-oldX; oldX=x;
glutPostRedisplay();
}

void myPrepareTexture(int i)//用參數來配, 找對應正確的變數
{//技巧3: 可以把重覆的東西, 用函式來簡化
    cvCvtColor(img[i], img[i], CV_BGR2RGB);
    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &id[i]);
    glBindTexture(GL_TEXTURE_2D, id[i]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img[i]->width, img[i]->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img[i]->imageData);
}
void myTexture()
{
    img[0]=cvLoadImage("imgbody.png");
    img[1]=cvLoadImage("imgHand1.png");
    img[2]=cvLoadImage("imgLeg1.png");
    for(int i=0;i<3;i++){//技巧2: 可以把重覆的東西, 用迴圈來簡化
        myPrepareTexture(i);
    }
}
void myPolygon(int num){//技巧3: 可以把重覆的東西, 用函式來簡化
    glPushMatrix();
        glScalef(0.3, 0.8, 0.8);
        glBindTexture(GL_TEXTURE_2D, id[num]);
        glBegin(GL_POLYGON);
            glTexCoord2f(0, 0);   glVertex3f( -0.5,  0.5, 0);
            glTexCoord2f(1, 0);   glVertex3f(  0.5,  0.5, 0);  
            glTexCoord2f(1, 1);   glVertex3f(  0.5, -0.5, 0);  
            glTexCoord2f(0, 1);   glVertex3f( -0.5, -0.5, 0);  
        glEnd();
    glPopMatrix();
}
void myBody(){
glPushMatrix();
glScalef(0.7, 0.7, 0.7);
myPolygon(0);
glPopMatrix();
}
void myLeg(){
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
myPolygon(1);
glPopMatrix();
}
void myHand(){
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
myPolygon(2);
glPopMatrix();
}
void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        myBody();
   glPushMatrix();
       glTranslatef(0.1,0.1,0);//右手
       glRotatef(angle[1], 0,0,1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
       myHand();
    glPushMatrix();
       glTranslatef(0,-0.2,0);//右手1
       glRotatef(angle[2], 0,0,1);
       glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
        myHand();
  glPopMatrix();
   glPopMatrix();
   glPushMatrix();
       glTranslatef(-0.1,0.1,0);//左手
       glRotatef(-angle[3], 0,0,1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
       myHand();
   glPushMatrix();
       glTranslatef(0,-0.2,0);//左手1
       glRotatef(-angle[4], 0,0,1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
       myHand();
   glPopMatrix();
   glPopMatrix();
   glPushMatrix();
       glTranslatef(-0.1,-0.2,0);//左腿
       glRotatef(-angle[5], 0,0,1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
    glPushMatrix();
       glTranslatef(0,-0.2,0);//左腿1
       glRotatef(-angle[6], 0,0,1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
    myLeg();
    glPopMatrix();
   glPopMatrix();
   glPushMatrix();
       glTranslatef(0.1,-0.2,0);//右腿
       glRotatef(-angle[7], 0,0,-1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
       myLeg();
       glPushMatrix();
       glTranslatef(0,-0.2,0);//右腿1
       glRotatef(-angle[8], 0,0,-1);
   glutWireSphere(0.1,20,20);
       glTranslatef(0, -0.2, 0);
      myLeg();
    glPopMatrix();
   glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
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=='5') angleID=5;
if(key=='6') angleID=6;
if(key=='7') angleID=7;
if(key=='8') angleID=8;
glutPostRedisplay();

}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
myTexture();//不要忘了加哦!
glutMainLoop();
}

2014年5月1日 星期四

week11


#include <Gl/glut.h>
float teapotX=0,teapotY=0;
void keyboard(unsigned char key, int x, int y)
{

    if(key=='a' || key=='A') teapotX+=3;
    if(key=='b' || key=='B') teapotX-=3;


    glutPostRedisplay();
}

void display()
{
glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(teapotX,0,1,0.2);
        glutWireTeapot(0.3);
     
        glPushMatrix();
       glTranslatef(0.5,0,0);
       glutSolidSphere(0.2,30,30);
        glPopMatrix();
     
        glPushMatrix();
       glTranslatef(-0.5,0,0);
       glutSolidSphere(0.2,30,30);
        glPopMatrix();
     
        glPushMatrix();
       glTranslatef(0,0.5,0);
       glutSolidSphere(0.2,30,30);
        glPopMatrix();
     
        glPushMatrix();
       glTranslatef(0,-0.5,0);
       glutSolidSphere(0.2,30,30);
        glPopMatrix();
     
    glPopMatrix();

    glutSwapBuffers();
}
void myLight()
{
    const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
int main()
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week10");
 
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    myLight();

    glutMainLoop();
}

2014年4月24日 星期四

week10


#include <Gl/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0;
float angleX=0,startX=0;
void keyboard(unsigned char key, int x, int y)
{
printf("%c %d %d\n",key, x, y);
if(key=='a' || key=='A') teapotX+=0.1;
if(key=='b' || key=='B') teapotX-=0.1;
if(key=='c' || key=='C') teapotY+=0.1;
if(key=='d' || key=='D') teapotY-=0.1;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button ,state ,x ,y);
}

void motion(int x, int y)
{
printf("%d %d\n", x, y);
angleX+=(x-startX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
glRotatef(angleX,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);

glutMainLoop();
}

2014年4月10日 星期四

week08

#include <Gl/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
GLUquadric * quad=NULL;
float angle=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glRotatef(angle,0,0,1);

gluQuadricTexture(quad, true);
gluSphere(quad,0.8,30,30);
glPopMatrix();

glutSwapBuffers();
}
void idle()
{
angle++;
glutPostRedisplay();
}

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week08");
glutDisplayFunc(display);
glutIdleFunc(idle);

GLuint id;
IplImage* img = cvLoadImage("earth.jpg");
cvCvtColor(img,img,CV_BGR2RGB);
glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D,id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
   
    quad = gluNewQuadric();
glutMainLoop();
}

2014年3月27日 星期四

week06

//NEW!
GLuint id;
IplImage* img = cvLoadImage("earth.jpg");
cvCvtColor(img,img,CV_BGR2RGB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,id);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);
//NEW!!