This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------------------------------------------ | |
基本図形による3D描画の実施 | |
--------------------------------------------------------*/ | |
#include <GL/glut.h> | |
#include <iostream> | |
// 描画処理が必要なときに呼ばれる | |
void display(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); // カラーバッファを初期化する | |
glColor3f(0.0f, 0.0f, 1.0f); // これから描画する図形の色は青 | |
glutWireCube(5.0); // ワイヤーフレーム立方体を描画 | |
glFlush(); // 描画を行う | |
} | |
// ウィンドウのサイズ変更時に呼ばれる | |
void reshape(int width, int height) { | |
// ① ビューポートの設定 | |
glViewport(0, 0, width, height); | |
// ② 視野領域の決定 | |
glMatrixMode(GL_PROJECTION); // 射影行列を操作する | |
glLoadIdentity(); // 行列を初期化 | |
gluPerspective(60.0, (double)width / height, 1.0, 100.0); | |
// ③ 視点位置の決定 | |
glMatrixMode(GL_MODELVIEW); // モデルビュー行列の設定 | |
glLoadIdentity(); // 行列を初期化 | |
gluLookAt(7.0, 5.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
} | |
void initialize(void) | |
{ | |
glClearColor(1.0, 1.0, 1.0, 1.0); // 画面を白にする | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); // GLUTを初期化する | |
glutInitWindowSize(800, 600); // 画面サイズを指定する | |
glutInitWindowPosition(100, 100); // 画面の初期位置を指定する | |
glutInitDisplayMode(GLUT_RGBA); // 表示モード設定 | |
glutCreateWindow("OpenGL Window"); // ウィンドウの名前 | |
// コールバック関数の設定 | |
glutDisplayFunc(display); // 描画処理が必要なときに呼ばれる | |
glutReshapeFunc(reshape); // reshapeが必要なときに呼ばれる | |
initialize(); // 初期化 | |
glutMainLoop(); // 毎フレームのLoop | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment