Week12
step01
程式碼:
| #include <stdio.h> | |
| int main() | |
| { | |
| FILE * fout = fopen("file.txt","w"); | |
| printf("Hello World\n"); | |
| fprintf(fout,"Hello World在檔案裡\n"); | |
| } |
程式碼:
| #include <stdio.h> | |
| int main() | |
| { | |
| FILE * fin = fopen("file.txt", "r"); | |
| char line[100]; | |
| fscanf(fin, "%s" , line); | |
| printf("從file.txt讀到了: %s\n",line); | |
| fscanf(fin , "%s" , line); | |
| printf("從file.txt讀到了: %s\n",line); | |
| } |
step04
執行 :
(讀取到空格 所以字分開)
程式碼:
| #include <stdio.h> | |
| int main() | |
| { | |
| int a[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; | |
| int b[10] = {}; | |
| FILE * fout = fopen("file3.txt","w"); | |
| for(int i=0 ; i<10 ; i++) | |
| { | |
| printf("%d ",a[i]); | |
| fprintf(fout,"%d ",a[i]); | |
| } | |
| printf("\n"); | |
| fprintf(fout,"\n"); | |
| fclose(fout); | |
| FILE * fin = fopen("file3.txt","r"); | |
| for(int i=0 ; i<10 ; i++) | |
| { | |
| fscanf(fin,"%d", &b[i]); | |
| printf("b%d:%d ",i, b[i]); | |
| } | |
| fclose(fin); | |
| } |
step05
執行:
step06
程式碼:
#include <stdio.h> #include <GL/glut.h> float teapotX=0 , teapotY=0; 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) { if(state==GLUT_DOWN) { 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(); }
| #include <stdio.h> | |
| #include <GL/glut.h> | |
| float teapotX=0 , teapotY=0; | |
| 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) | |
| { | |
| if(state==GLUT_DOWN) | |
| { | |
| 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(); | |
| } |
(用滑鼠點會移動位置)
step07
(座標點會存在檔案總管中(freeglut/bin)資料夾裡面)
執行 :
(按滑鼠的畫面)
(按空白鍵畫面會重複一次)
程式碼:
| #include <stdio.h> | |
| #include <GL/glut.h> | |
| FILE * fout = NULL; | |
| FILE * fin = NULL; | |
| float teapotX=0 , teapotY=0; | |
| 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) | |
| { | |
| if(state==GLUT_DOWN) | |
| { | |
| teapotX = (x-150)/150.0; | |
| teapotY = (150-y)/150.0; | |
| 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); | |
| glutMouseFunc(mouse); | |
| glutKeyboardFunc(keyboard); | |
| glutMainLoop(); | |
| } |
step08
工作目錄不合理,要修改
step09
將freeglut.dill複製到專案裡
需要修改 (Release)


















沒有留言:
張貼留言