如果想貼一張以上貼圖
貼圖盡量2n*2n會比較好 (EX:256*256)
1.先宣告兩個變數 GLuint tex1,tex2;
在main()裡
tex1=myTexture("data/Diffuse.jpg");
tex2=myTexture("data/Wood.png");
2.在void display()裡
glBindTexture(GL_TEXTURE_2D,tex1);
glBindTexture(GL_TEXTURE_2D,tex2);
模型被壓扁要開3D前後深度測試
攝影機與運鏡 : 透視投影法 glyPerspective,配上glutReshapeFunc()再上gluLookAt()
void reshape(int w,int h){///不能 整數除
float ar = (float) w/(float) h;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);///3D變2D
glLoadIdentity();
gluPerspective(60,ar,0.1,100);
glMatrixMode(GL_MODELVIEW);///3D Model+view
glLoadIdentity();
gluLookAt(0,0,3,
0,0,0, ///center看哪裡
0,1,0);///up向量
}
兩張貼圖 : Gundam(鋼彈)、木紋、宣告2個整數 GLuint tex1、text2; 在main()裡面
text1 = myTexture("data/Diffuse.jpg");
text2 = myTexture("data/wood.png");
在 display() 裡
glBindTexture(GL_TEXTUTE_2D, text1) 及 glBindTexture(GL_TEXTURE_2D, text2) 來切換
把全部的模型讀入 : 改寫 myReadGundam() 改寫 myReadOne() 及 myReadAll();
TRT :
必須有中心點
可以使用 mouse motion 來知道值在哪裡
void myWrite()
{
if(fout == NULL)fout=fopen("file.txt","w+");
for(int i = 0;i<20;i++)
{
printf("%.1f",angle[i]);///小黑印出來
fprintf(fout,"%.1f",angle[i]);///檔案印出來
}///這裡老師沒有fclose
}
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;
}
void mouse(int button,int state,int x,int y)
{
oldX=x;
}
void motion(int x,int y)
{
angle[angleID]+=(x-oldX);
myWrite();
oldX=x;
glutPostRedisplay();
}
沒有留言:
張貼留言