Modified lines:  7, 16, 22, 25, 54
Added line:  41, 42, 43, 44, 45, 46, 47, 48, 63
Removed line:  None
Generated by diff2html.pl
© Yves Bailly, MandrakeSoft S.A. 2001, Ryohei Morita 2007
diff2html.pl is licensed under the GNU GPL.

  ../06-03/06-03-SwapBuffersCheck.c     06-04-SwapByTimer.c
  75 lines
2317 bytes
Last modified : Wed Dec 14 12:26:37 2011

    84 lines
2803 bytes
Last modified : Wed Dec 14 13:14:12 2011

1 // Keisanki Joron 2 (Introduction to Computing II)   1 // Keisanki Joron 2 (Introduction to Computing II)
2 // Dept. of Engineering Systems, University of Tsukuba   2 // Dept. of Engineering Systems, University of Tsukuba
3 // [UTF-8 / Unix]   3 // [UTF-8 / Unix]
4 // 計算機序論2・実習 (筑波大学工学システム学類)   4 // 計算機序論2・実習 (筑波大学工学システム学類)
5   5
6 // 2011/12/02a kameda[at]iit.tsukuba.ac.jp   6 // 2011/12/02a kameda[at]iit.tsukuba.ac.jp
7 // 06.03. はじめてのOpenGL - バッファ切替の確認 -   7 // 06.04. はじめてのOpenGL - バッファを時間で切り替え -
8   8
9 #include <stdio.h> // printf()   9 #include <stdio.h> // printf()
10 #include <GL/glut.h> // gl*(), glut*()   10 #include <GL/glut.h> // gl*(), glut*()
11   11
12 // +----------------------------------------------------   12 // +----------------------------------------------------
13 // 1フレーム分の描画   13 // 1フレーム分の描画
14 // +----------------------------------------------------   14 // +----------------------------------------------------
15 void ic2_DrawFrame (void) {   15 void ic2_DrawFrame (void) {
16   static int loopmax = 3; // loopmax回ごとに1回色を変える   16   static int loopmax = 4; // loopmax回ごとに1回色を変える
17   static int loopcounter = 0; // 何回目かを覚えておく変数   17   static int loopcounter = 0; // 何回目かを覚えておく変数
18   18
19   // (0) 指定色の変更   19   // (0) 指定色の変更
20   loopcounter++;   20   loopcounter++;
21   if (loopcounter == loopmax) {   21   if (loopcounter == loopmax) {
22     glClearColor(0.0, 1.0, 0.0, 0.0); // 3回に1回は緑   22     glClearColor(0.0, 1.0, 0.0, 0.0); // 4回に1回は緑
23     loopcounter = 0;   23     loopcounter = 0;
24   } else {   24   } else {
25     glClearColor(0.0, 0.0, 0.0, 0.0); // 3回に2回は黒   25     glClearColor(0.0, 0.0, 0.0, 0.0); // 4回に3回は黒
26   }   26   }
27   27
28   // (1) 描画バッファの初期化   28   // (1) 描画バッファの初期化
29   // 以前にglClearColor()で指定した色で塗り潰す   29   // 以前にglClearColor()で指定した色で塗り潰す
30   glClear(GL_COLOR_BUFFER_BIT);   30   glClear(GL_COLOR_BUFFER_BIT);
31   31
32   // (2) カメラの設定   32   // (2) カメラの設定
33   // (3) 光源の設置   33   // (3) 光源の設置
34   // (4) 物体の描画   34   // (4) 物体の描画
35   35
36   // (5) 描画バッファの切替   36   // (5) 描画バッファの切替
37   glutSwapBuffers();   37   glutSwapBuffers();
38 }   38 }
39   39
40 // +----------------------------------------------------   40 // +----------------------------------------------------
      41 // タイマーで呼出し(繰り返すことで「一定間隔呼出し」化)
      42 // +----------------------------------------------------
      43 void ic2_timerhandler(int keynumber){
      44   glutPostRedisplay(); // OpenGLのmainloopに戻ったら再描画を頼む
      45   glutTimerFunc(250, ic2_timerhandler, 0); // 250[ms]後にまた呼び出す
      46 }
      47
      48 // +----------------------------------------------------
41 // OpenGLとしてのWindowの初期化   49 // OpenGLとしてのWindowの初期化
42 // +----------------------------------------------------   50 // +----------------------------------------------------
43 void ic2_BootWindow (char winname[]) {   51 void ic2_BootWindow (char winname[]) {
44   52
45   // DisplayModeの設定(それぞれを|で繋ぐ)   53   // DisplayModeの設定(それぞれを|で繋ぐ)
46   //   GLUT_DOUBLE ... ダブルバッファ   54   //   GLUT_DOUBLE ... ダブルバッファ
47   //   GLUT_RGB    ... RGB表色モード   55   //   GLUT_RGB    ... RGB表色モード
48   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);    56   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); 
49   57
50   // 準備(Initialization)が済んだらウィンドウを開く   58   // 準備(Initialization)が済んだらウィンドウを開く
51   glutCreateWindow(winname);   59   glutCreateWindow(winname);
52   60
53   // Callback関数を設定 (イベント処理)   61   // Callback関数を設定 (イベント処理)
54   glutIdleFunc(ic2_DrawFrame); // 暇だったら1フレーム描く(よい実装ではない)   62   glutDisplayFunc(ic2_DrawFrame); // フレームを(再)描画するために呼び出す関数
      63   glutTimerFunc(250, ic2_timerhandler, 0); // 250[ms]後に呼び出す関数
55   64
56   // ウィンドウ全体を書き直すときの色(R,G,B,0) ここでは黒   65   // ウィンドウ全体を書き直すときの色(R,G,B,0) ここでは黒
57   glClearColor(0.0, 0.0, 0.0, 0.0);   66   glClearColor(0.0, 0.0, 0.0, 0.0);
58 }   67 }
59   68
60 // +----------------------------------------------------   69 // +----------------------------------------------------
61 // Main Function   70 // Main Function
62 // +----------------------------------------------------   71 // +----------------------------------------------------
63 int main (int argc, char *argv[]) {   72 int main (int argc, char *argv[]) {
64   73
65   // glutライブラリによる引数の解釈   74   // glutライブラリによる引数の解釈
66   glutInit(&argc, argv);   75   glutInit(&argc, argv);
67   76
68   // OpenGL Window の初期化   77   // OpenGL Window の初期化
69   ic2_BootWindow(argv[0]);   78   ic2_BootWindow(argv[0]);
70   79
71   // 無限ループの開始   80   // 無限ループの開始
72   glutMainLoop();   81   glutMainLoop();
73      82   
74   return 0;   83   return 0;
75 }   84 }

Generated by diff2html.pl on Mon Oct 29 12:22:57 2012
Command-line:
/home/ubuntu/scripts/diff2html_utf.pl ../06-03/06-03-SwapBuffersCheck.c 06-04-SwapByTimer.c