| 
 | Generated by UTF-8 version of diff2html.pl © Yves Bailly, MandrakeSoft S.A. 2001, Ryohei Morita 2007 diff2html.pl is licensed under the GNU GPL. | 
| ../06-02/06-02-SwapBuffers.c | 06-03-SwapBuffersCheck.c | |||
|---|---|---|---|---|
| 64 lines 1943 bytes Last modified : Wed Dec 14 04:20:22 2011 | 75 lines 2317 bytes Last modified : Wed Dec 14 12:26:38 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.02. はじめてのOpenGL - バッファを切り替えよう - | 7 | // 06.03. はじめての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回色を変える | |||
| 17 | static int loopcounter = 0; // 何回目かを覚えておく変数 | |||
| 18 | ||||
| 19 | // (0) 指定色の変更 | |||
| 20 | loopcounter++; | |||
| 21 | if (loopcounter == loopmax) { | |||
| 22 | glClearColor(0.0, 1.0, 0.0, 0.0); // 3回に1回は緑 | |||
| 23 | loopcounter = 0; | |||
| 24 | } else { | |||
| 25 | glClearColor(0.0, 0.0, 0.0, 0.0); // 3回に2回は黒 | |||
| 26 | } | |||
| 16 | 27 | |||
| 17 | // (1) 描画バッファの初期化 | 28 | // (1) 描画バッファの初期化 | |
| 18 | // 以前にglClearColor()で指定した色で塗り潰す | 29 | // 以前にglClearColor()で指定した色で塗り潰す | |
| 19 | glClear(GL_COLOR_BUFFER_BIT); | 30 | glClear(GL_COLOR_BUFFER_BIT); | |
| 20 | 31 | |||
| 21 | // (2) カメラの設定 | 32 | // (2) カメラの設定 | |
| 22 | // (3) 光源の設置 | 33 | // (3) 光源の設置 | |
| 23 | // (4) 物体の描画 | 34 | // (4) 物体の描画 | |
| 24 | 35 | |||
| 25 | // (5) 描画バッファの切替 | 36 | // (5) 描画バッファの切替 | |
| 26 | glutSwapBuffers(); | 37 | glutSwapBuffers(); | |
| 27 | } | 38 | } | |
| 28 | 39 | |||
| 29 | // +---------------------------------------------------- | 40 | // +---------------------------------------------------- | |
| 30 | // OpenGLとしてのWindowの初期化 | 41 | // OpenGLとしてのWindowの初期化 | |
| 31 | // +---------------------------------------------------- | 42 | // +---------------------------------------------------- | |
| 32 | void ic2_BootWindow (char winname[]) { | 43 | void ic2_BootWindow (char winname[]) { | |
| 33 | 44 | |||
| 34 | // DisplayModeの設定(それぞれを|で繋ぐ) | 45 | // DisplayModeの設定(それぞれを|で繋ぐ) | |
| 35 | // GLUT_DOUBLE ... ダブルバッファ | 46 | // GLUT_DOUBLE ... ダブルバッファ | |
| 36 | // GLUT_RGB ... RGB表色モード | 47 | // GLUT_RGB ... RGB表色モード | |
| 37 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | 48 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | |
| 38 | 49 | |||
| 39 | // 準備(Initialization)が済んだらウィンドウを開く | 50 | // 準備(Initialization)が済んだらウィンドウを開く | |
| 40 | glutCreateWindow(winname); | 51 | glutCreateWindow(winname); | |
| 41 | 52 | |||
| 42 | // Callback関数を設定 (イベント処理) | 53 | // Callback関数を設定 (イベント処理) | |
| 43 | glutIdleFunc(ic2_DrawFrame); // 暇だったら1フレーム描く(よい実装ではない) | 54 | glutIdleFunc(ic2_DrawFrame); // 暇だったら1フレーム描く(よい実装ではない) | |
| 44 | 55 | |||
| 45 | // ウィンドウ全体を書き直すときの色(R,G,B,0) ここでは黒 | 56 | // ウィンドウ全体を書き直すときの色(R,G,B,0) ここでは黒 | |
| 46 | glClearColor(0.0, 0.0, 0.0, 0.0); | 57 | glClearColor(0.0, 0.0, 0.0, 0.0); | |
| 47 | } | 58 | } | |
| 48 | 59 | |||
| 49 | // +---------------------------------------------------- | 60 | // +---------------------------------------------------- | |
| 50 | // Main Function | 61 | // Main Function | |
| 51 | // +---------------------------------------------------- | 62 | // +---------------------------------------------------- | |
| 52 | int main (int argc, char *argv[]) { | 63 | int main (int argc, char *argv[]) { | |
| 53 | 64 | |||
| 54 | // glutライブラリによる引数の解釈 | 65 | // glutライブラリによる引数の解釈 | |
| 55 | glutInit(&argc, argv); | 66 | glutInit(&argc, argv); | |
| 56 | 67 | |||
| 57 | // OpenGL Window の初期化 | 68 | // OpenGL Window の初期化 | |
| 58 | ic2_BootWindow(argv[0]); | 69 | ic2_BootWindow(argv[0]); | |
| 59 | 70 | |||
| 60 | // 無限ループの開始 | 71 | // 無限ループの開始 | |
| 61 | glutMainLoop(); | 72 | glutMainLoop(); | |
| 62 | 73 | |||
| 63 | return 0; | 74 | return 0; | |
| 64 | } | 75 | } |