-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathggsample01.cpp
More file actions
77 lines (57 loc) · 1.88 KB
/
ggsample01.cpp
File metadata and controls
77 lines (57 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// ゲームグラフィックス特論宿題アプリケーション
//
// 補助プログラムのラッパー
#include "GgApp.h"
// プロジェクト名
#if !defined(PROJECT_NAME)
# define PROJECT_NAME "ggsample01"
#endif
// 構成ファイル名
#if !defined(CONFIG_FILE)
# define CONFIG_FILE PROJECT_NAME "_config.json"
#endif
// 構成データ
#include "Config.h"
// メニューの描画
#include "Menu.h"
//
// アプリケーション本体
//
int GgApp::main(int argc, const char* const* argv)
{
// 設定を読み込む
const Config config{ CONFIG_FILE };
// ウィンドウを作成する
Window window{ argc > 1 ? argv[1] : PROJECT_NAME, config.getWidth(), config.getHeight() };
// メニューを初期化する
Menu menu{ config };
// 背景色を設定する
glClearColor(0.1f, 0.2f, 0.3f, 0.0f);
// 隠面消去処理を設定する
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
// ビュー変換行列を設定する
const GgMatrix mv{ ggLookat(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f) };
// ウィンドウが開いている間繰り返す
while (window)
{
// ウィンドウを消去する
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// メニューを表示する
menu.draw();
// オブジェクトの回転の変換行列を設定する
const auto& mr{ window.getRotationMatrix(0) };
// 視点の平行移動の変換行列を設定する
const auto& mt{ window.getTranslationMatrix(1) };
// 投影変換行列を設定する
const GgMatrix&& mp{ ggPerspective(0.5f, window.getAspect(), 1.0f, 15.0f) };
// シェーダを指定する
menu.getShader().use(mp, mt * mv * mr, menu.getLight());
// シーンを描画する
menu.getModel().draw();
// カラーバッファを入れ替えてイベントを取り出す
window.swapBuffers();
}
return 0;
}