2014 電腦圖學 Computer Graphics 授課教師: 葉正聖 銘傳大學資訊傳播工程系 每週主題: 程式環境、點線面顏色、移動/旋轉/縮放與矩陣(Matrix)、階層性關節轉動(T-R-T)、做出機器人、打光、貼圖、glu/glut函式、鍵盤、滑鼠、計時器(timer)、讀入3D模型、粒子系統、聲音、特效、投影矩陣、攝影機與運鏡、機器人2.0、期末作品
2014年6月12日 星期四
2014年5月30日 星期五
01160554
void readNext()
{
a+=0.1;
for(int i = 0 ; i < SIZE ; i++)
angle[i]=angleOld[i]*(1-a)+angleNew[i]*a;
}
void timer(int t)
{
glutTimerFunc(100, timer, 0);
readNext();
glutPostRedisplay();
}
bool isPlay = false;
void keyboard(unsigned char key,int x,int y)
{
if(key=='r')
{
readNext();
glutPostRedisplay();
}
else if(!isPlay && key == 'p')
{
isPlay = true;
glutTimerFunc(0, timer, 0);
}
}
2014年5月23日 星期五
01160554
Download header
https://www.dropbox.com/s/etmgonhg7a2xrja/CMP3_MCI.h
#include <Windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include "CMP3_MCI.h"
//#pragma comment(lib,"winmm.lib") //using lib
CMP3_MCI mp3;
int main()
{
//PlaySound("0078.WAV", NULL, SND_SYNC); //<-Windows API
mp3.Load("lick.mp3");
mp3.Play();
getchar(); //pause console
}
timer
FILE *out = NULL;
FILE *in = NULL;
void timer(int)
{
if(!in)
in = fopen("out.txt", "r+");
for(int i = 0 ; i < SIZE ; i++)
{
fscanf(in, "%f", &angle[i]);
printf("%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
if(in && !feof(in))
glutTimerFunc(100,timer, 0);
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='0') angleID=0;
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(!out)
out = fopen("out.txt", "w+");
for(int i = 0 ; i < SIZE ; i++)
{
fprintf(stdout, "%-8.2f", angle[i]);
fprintf(out, "%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
fprintf(out, "\n");
}
if(key=='r')
{
if(!in)
in = fopen("out.txt", "r+");
for(int i = 0 ; i < SIZE ; i++)
{
fscanf(in, "%f", &angle[i]);
printf("%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
}
if(key=='p')
glutTimerFunc(1000,timer, 0);
glutPostRedisplay();//請電腦重新畫一次畫面
}
https://www.dropbox.com/s/etmgonhg7a2xrja/CMP3_MCI.h
#include <Windows.h>
#include <mmsystem.h>
#include <stdio.h>
#include "CMP3_MCI.h"
//#pragma comment(lib,"winmm.lib") //using lib
CMP3_MCI mp3;
int main()
{
//PlaySound("0078.WAV", NULL, SND_SYNC); //<-Windows API
mp3.Load("lick.mp3");
mp3.Play();
getchar(); //pause console
}
timer
FILE *out = NULL;
FILE *in = NULL;
void timer(int)
{
if(!in)
in = fopen("out.txt", "r+");
for(int i = 0 ; i < SIZE ; i++)
{
fscanf(in, "%f", &angle[i]);
printf("%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
if(in && !feof(in))
glutTimerFunc(100,timer, 0);
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='0') angleID=0;
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(!out)
out = fopen("out.txt", "w+");
for(int i = 0 ; i < SIZE ; i++)
{
fprintf(stdout, "%-8.2f", angle[i]);
fprintf(out, "%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
fprintf(out, "\n");
}
if(key=='r')
{
if(!in)
in = fopen("out.txt", "r+");
for(int i = 0 ; i < SIZE ; i++)
{
fscanf(in, "%f", &angle[i]);
printf("%-8.2f", angle[i]);
}
fprintf(stdout, "\n");
}
if(key=='p')
glutTimerFunc(1000,timer, 0);
glutPostRedisplay();//請電腦重新畫一次畫面
}
2014年5月16日 星期五
01160554
#include <GL/glut.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
float angle[8]={};
int angleID=0;
GLuint id[4];//技巧2: 使用陣列, 讓變數 變 簡單 simple
IplImage * img[4];
char filename[4][100]={"imgBody.png", "imgHand0.png", "imgLeg0.png", "imgLeg1.png"};
void myTexture()
{
glEnable(GL_TEXTURE_2D);
for(int i=0; i<4; i++){//技巧3: 迴圈, 可以讓程式碼, 做重覆的事可以很爽 清爽
img[i] = cvLoadImage( filename[i] );
cvCvtColor(img[i], img[i], CV_BGR2RGB);
glGenTextures(1, &id[i]);
glBindTexture(GL_TEXTURE_2D, id[i]);//head
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 myRect()//技巧1: 重覆的程式碼, 用函式拉出來, 就不用一直copy啦
{//函式就是 黑盒子 幫你做事情!
glPushMatrix();
glScalef(0.2, 0.5, 0.5);
glBegin(GL_POLYGON);
glTexCoord2f(0,0); glVertex3f(-0.5, 0.5,0);
glTexCoord2f(0,1); glVertex3f(-0.5,-0.5,0);
glTexCoord2f(1,1); glVertex3f( 0.5,-0.5,0);
glTexCoord2f(1,0); glVertex3f( 0.5, 0.5,0);
glEnd();
glPopMatrix();
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, id[0]);
myRect();//body//技巧1: 用函式, 哥就是帥!
glPushMatrix();//left hand 今天的技巧1: 大的手
glTranslatef(-0.1, 0.15, 0);
glRotatef(angle[0], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();// 今天的技巧2: 小的手
glTranslatef(0, -0.25, 0);//(3) T: 掛在該掛的位子
glRotatef(angle[1], 0,0,1);//(2) R:
glTranslatef(0, -0.25, 0);//(1) T: 改變旋轉軸的位置
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//right hand
glTranslatef(0.1, 0.15, 0);
glRotatef(-angle[2], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();// 今天的技巧2: 小的手
glTranslatef(0, -0.25, 0);//(3) T: 掛在該掛的位子
glRotatef(-angle[3], 0,0,1);//(2) R:
glTranslatef(0, -0.25, 0);//(1) T: 改變旋轉軸的位置
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//left leg
glTranslatef( -0.05, -0.25, 0);
glRotatef(180-angle[4], 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//left foot
glTranslatef( 0, 0.25, 0);
glRotatef(angle[5], 0,0,1);
glTranslatef(0, 0.15, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//right leg
glTranslatef( 0.05, -0.25, 0);
glRotatef(-(180-angle[6]), 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//left foot
glTranslatef( 0, 0.25, 0);
glRotatef(-angle[7], 0,0,1);
glTranslatef(0, 0.15, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='0') angleID=0;
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 oldX=0, oldY=0;
void mouse(int button, int state, int x, int y)
{
oldX=x; oldY=y;
}
void motion(int x, int y)
{
angle[angleID] += x-oldX; oldX=x;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
myTexture();
glutMainLoop();
}
#include <opencv/highgui.h>
#include <opencv/cv.h>
float angle[8]={};
int angleID=0;
GLuint id[4];//技巧2: 使用陣列, 讓變數 變 簡單 simple
IplImage * img[4];
char filename[4][100]={"imgBody.png", "imgHand0.png", "imgLeg0.png", "imgLeg1.png"};
void myTexture()
{
glEnable(GL_TEXTURE_2D);
for(int i=0; i<4; i++){//技巧3: 迴圈, 可以讓程式碼, 做重覆的事可以很爽 清爽
img[i] = cvLoadImage( filename[i] );
cvCvtColor(img[i], img[i], CV_BGR2RGB);
glGenTextures(1, &id[i]);
glBindTexture(GL_TEXTURE_2D, id[i]);//head
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 myRect()//技巧1: 重覆的程式碼, 用函式拉出來, 就不用一直copy啦
{//函式就是 黑盒子 幫你做事情!
glPushMatrix();
glScalef(0.2, 0.5, 0.5);
glBegin(GL_POLYGON);
glTexCoord2f(0,0); glVertex3f(-0.5, 0.5,0);
glTexCoord2f(0,1); glVertex3f(-0.5,-0.5,0);
glTexCoord2f(1,1); glVertex3f( 0.5,-0.5,0);
glTexCoord2f(1,0); glVertex3f( 0.5, 0.5,0);
glEnd();
glPopMatrix();
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, id[0]);
myRect();//body//技巧1: 用函式, 哥就是帥!
glPushMatrix();//left hand 今天的技巧1: 大的手
glTranslatef(-0.1, 0.15, 0);
glRotatef(angle[0], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();// 今天的技巧2: 小的手
glTranslatef(0, -0.25, 0);//(3) T: 掛在該掛的位子
glRotatef(angle[1], 0,0,1);//(2) R:
glTranslatef(0, -0.25, 0);//(1) T: 改變旋轉軸的位置
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//right hand
glTranslatef(0.1, 0.15, 0);
glRotatef(-angle[2], 0,0,1);
glTranslatef(0, -0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[1]);
myRect();//技巧1: 用函式, 哥就是帥!
glPushMatrix();// 今天的技巧2: 小的手
glTranslatef(0, -0.25, 0);//(3) T: 掛在該掛的位子
glRotatef(-angle[3], 0,0,1);//(2) R:
glTranslatef(0, -0.25, 0);//(1) T: 改變旋轉軸的位置
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//left leg
glTranslatef( -0.05, -0.25, 0);
glRotatef(180-angle[4], 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//left foot
glTranslatef( 0, 0.25, 0);
glRotatef(angle[5], 0,0,1);
glTranslatef(0, 0.15, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();
glPopMatrix();
glPushMatrix();//right leg
glTranslatef( 0.05, -0.25, 0);
glRotatef(-(180-angle[6]), 0,0,1);
glTranslatef(0, 0.25, 0);
glBindTexture(GL_TEXTURE_2D, id[2]);
myRect();
glPushMatrix();//left foot
glTranslatef( 0, 0.25, 0);
glRotatef(-angle[7], 0,0,1);
glTranslatef(0, 0.15, 0);
glBindTexture(GL_TEXTURE_2D, id[3]);
myRect();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='0') angleID=0;
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 oldX=0, oldY=0;
void mouse(int button, int state, int x, int y)
{
oldX=x; oldY=y;
}
void motion(int x, int y)
{
angle[angleID] += x-oldX; oldX=x;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
myTexture();
glutMainLoop();
}
2014年5月9日 星期五
01160554 linking opencv to dev-c
linking opencv to dev-c
1.install dev-c packet
2. add param
專案->專案設定->參數->add -lcv -lcxcore -lhighgui
1.install dev-c packet
專案->專案設定->參數->add -lcv -lcxcore -lhighgui
3. copy dev/bin/opencv all dll to current directory
//////////////////////////////////////////////////////
in coding
void myTexture()
{
GLuint id;
IplImage * img = cvLoadImage("0960140072.jpg");
cvCvtColor(img, img, CV_BGR2RGB);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &id);
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);
}
int main()
{
//...
myTexture();
//...
}
2014年5月2日 星期五
01160554
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angleX, 0,1,0);
glutWireTeapot(0.3);
glPushMatrix();//右肩
glTranslatef(0.5, 0, 0);
glutSolidSphere(0.2, 30, 30);
glPushMatrix();
glRotatef(angle2, 0, 0, 1);
glTranslatef(0.2, 0, 0);
glScalef(0.4, 0.2, 0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPushMatrix();//左肩
glTranslatef(-0.5, 0, 0);
glutSolidSphere(0.2, 30, 30);
glPushMatrix();
glRotatef(angle2, 0, 0, 1);
glTranslatef(-0.2, 0, 0);
glScalef(0.4, 0.2, 0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
//here
glPushMatrix();
glTranslatef(0.2, -0.3, 0);
glRotatef(angle3, 0, 0, 1);
glTranslatef(0, -0.25, 0);
glPushMatrix();
glScalef(0.2, 0.5, 0.2);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(0, 0.5, 0);
glutSolidSphere(0.2, 30, 30);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
2014年4月11日 星期五
01160554
#include <GL/glut.h>
#include "glm.h"
float angle = 0;
GLMmodel* pmodel = NULL;
void head()
{
glPushMatrix();
glTranslatef(0, 0.3, 0);
glColor3f(0, 0, 1);
glutSolidSphere(0.3, 30, 30);
glColor3f(1, 1, 1);
glTranslatef(0, -0.01, 0.1);
glutSolidSphere(0.25, 30, 30);
glPopMatrix();
}
void eye()
{
glPushMatrix();
glColor3f(1, 1, 1);
glutSolidSphere(0.1, 20, 20);
glColor3f(0, 0, 0);
glTranslatef(0, 0, 0.1);
glutSolidSphere(0.02, 10, 10);
glPopMatrix();
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0, 1, 0);
glRotatef(-90, 1, 0, 0);
glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL);
glPopMatrix();
glutSwapBuffers();
}
void idle()
{
angle++;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
if(key == ' ')
angle+=20;
glutPostRedisplay();
}
//燈光位置設定
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };
int main()
{
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("week08");
glutDisplayFunc(display);
glutIdleFunc(idle);//閒置時執行
glutKeyboardFunc(keyboard);
//開啟燈光
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
//燈光位置
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//讀取obj檔
pmodel = glmReadOBJ("bear.obj");
glmUnitize(pmodel);
glmFacetNormals(pmodel);
glmVertexNormals(pmodel, 90.0);
glutMainLoop();
}
//////////////////////////////
timer作法
void timer(int t)
{
glutTimerFunc(10, timer, t+1);
angle += 5;
glutPostRedisplay();
}
int main()
{
///....
glutTimerFunc(1500, timer, 0);
///....
}
2014年3月28日 星期五
01160554陳聲華
1. Install opencv Packet
2. linker setting -> -lcv -lcxcore -lhighgui
3. copy dll to project directory
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <GL/glut.h>
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week06");
glutDisplayFunc(display);
glEnable(GL_TEXTURE_2D);
IplImage *img = cvLoadImage("earth.jpg", -1);
cvCvtColor(img, img, CV_BGR2RGB);
GLuint id;
glGenTextures(1, &id);
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);
glutMainLoop();
}
2. linker setting -> -lcv -lcxcore -lhighgui
3. copy dll to project directory
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <GL/glut.h>
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week06");
glutDisplayFunc(display);
glEnable(GL_TEXTURE_2D);
IplImage *img = cvLoadImage("earth.jpg", -1);
cvCvtColor(img, img, CV_BGR2RGB);
GLuint id;
glGenTextures(1, &id);
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);
glutMainLoop();
}
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <GL/glut.h>
GLuint id;
float rot = 0;
GLUquadric *quad = NULL;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(90, 1, 0, 0);
glRotatef(rot, 0, 0, 1);
gluQuadricTexture(quad, true);
gluSphere(quad, 1, 30, 30);
glPopMatrix();
glutSwapBuffers();
}
void idle()
{
rot++;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week06");
glutDisplayFunc(display);
glutIdleFunc(idle);
glEnable(GL_TEXTURE_2D);
IplImage *img = cvLoadImage("earth.jpg", -1);
cvCvtColor(img, img, CV_BGR2RGB);
GLuint id;
glGenTextures(1, &id);
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月21日 星期五
2014年3月14日 星期五
2014年3月7日 星期五
01160554陳聲華
座標算法:正三角形的重心位置設為(0, 0),上面的點設為(0, 1),利用一些角度公式算出右邊的座標為(0.87, 0.5)左邊座標為(-0.87, 0.5),這樣湊出一樣正三角形,接著只要再做出一個三角形,正負號顛倒就能湊出一個完美的六角形。
2014年2月21日 星期五
訂閱:
文章 (Atom)
