Week12-1 Printf fprintf
2.寫入程式碼,可生成文字檔並寫出 hello world
Week12-2
1.在開新empty file ,但其程式目錄要和week12-1要在同個目錄,因為接下來程式碼要讀取week12-1生成的文字檔
2.寫入程式,並執行測試是否能讀取 file.txt 裡的文字
Week12-3
1.先直接創建檔案 Empty file,並寫入程式,要創建一個文字檔,裡面有程式給予的指定數字列。
2.
Week12-4 Keyboard-mouse
:#include<stdio.h>
#include<GL/glut.h>
float teapotX=0,teapotY=0;
FILE * fout = NULL;
FILE * fin = NULL;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
teapotX=(x-150)/150.0;
teapotY=(150-y)/150.0;
display();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
2.透過滑鼠的點擊來讓茶壺移動
void mouse(int button,int state,int x,int y)
{
teapotX=(x-150)/150.0;
teapotY=(150-y)/150.0;
if(state==GLUT_DOWN)
{
if(fout==NULL) fout=fopen("file4.txt","w");
fprintf(fout,"%f %f\n",teapotX,teapotY);
}
display();
}
void keyboard(unsigned char key,int x,int y)
{
if(fin==NULL)
{
fclose(fout);
fin = fopen("file4.txt","r");
}
fscanf(fin,"%f%f",&teapotX,&teapotY);
display();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week12");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
2.在接下來的視窗點進 Build targets > Execution working dir
Week12-5 Final Project備份
1.複製week12-4的整個專案,並將裡面的 .cbp檔改名成Final project並開啟
修改Title列改名為 Final Project 並儲存
沒有留言:
張貼留言