質問編集履歴
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,557 +1,34 @@
|
|
1
1
|
### 問題(Problem)
|
2
|
-
|
3
2
|
* glfw3を使って、ウィンドウを表示させたいのですが、
|
4
|
-
|
5
|
-
|
6
3
|
|
7
4
|
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
8
5
|
|
9
|
-
|
10
|
-
|
11
6
|
というエラーが出て、表示する途中で落ちてしまいます。
|
12
|
-
|
13
7
|
どうすれば解決できるでしょうか?
|
14
|
-
|
15
|
-
|
16
8
|
|
17
9
|
* My program has a error with glfw3 window. The error is that
|
18
10
|
|
19
|
-
|
20
|
-
|
21
11
|
ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
22
|
-
|
23
|
-
|
24
12
|
|
25
13
|
How can I deal with it?
|
26
14
|
|
27
|
-
|
28
|
-
|
29
15
|
### 発生している問題・エラーメッセージ(Error)
|
30
16
|
|
31
|
-
|
32
|
-
|
33
17
|
```
|
34
|
-
|
35
18
|
Main[74526:7122089] [General] ERROR: Setting <GLFWContentView: 0x1007508a0> as the first responder for window <GLFWWindow: 0x10072f620>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.
|
36
|
-
|
37
19
|
(
|
38
|
-
|
39
20
|
0 AppKit 0x00007fff5520752e -[NSWindow _validateFirstResponder:] + 578
|
40
|
-
|
41
21
|
1 AppKit 0x00007fff5494ea58 -[NSWindow _setFirstResponder:] + 31
|
42
|
-
|
43
22
|
2 AppKit 0x00007fff549ed17d -[NSWindow _realMakeFirstResponder:] + 448
|
44
|
-
|
45
23
|
3 Main 0x0000000100055003 createNativeWindow + 1187
|
46
|
-
|
47
24
|
4 Main 0x000000010005490f _glfwPlatformCreateWindow + 63
|
48
|
-
|
49
25
|
5 Main 0x000000010004d167 glfwCreateWindow + 887
|
50
|
-
|
51
26
|
6 Main 0x000000010000caa1 _ZN6WindowC2EiiPKc + 97
|
52
|
-
|
53
27
|
7 Main 0x0000000100008e59 _ZN6WindowC1EiiPKc + 41
|
54
|
-
|
55
28
|
8 Main 0x000000010000855c main + 156
|
56
|
-
|
57
29
|
9 libdyld.dylib 0x00007fff7ebc4115 start + 1
|
58
|
-
|
59
30
|
)
|
60
|
-
|
61
|
-
|
62
31
|
|
63
32
|
```
|
64
33
|
|
65
34
|
|
66
|
-
|
67
|
-
### 該当のソースコード
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```c++
|
72
|
-
|
73
|
-
#include <GL/glew.h>
|
74
|
-
|
75
|
-
#include <GLFW/glfw3.h>
|
76
|
-
|
77
|
-
#include <chrono>
|
78
|
-
|
79
|
-
#include <iostream>
|
80
|
-
|
81
|
-
#include <thread>
|
82
|
-
|
83
|
-
#include "./MendelsEngine/Model/UI/Window.h"
|
84
|
-
|
85
|
-
#include "./MendelsEngine/State/Scene/Scene.h"
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
/* 変数名の省略の対応表
|
90
|
-
|
91
|
-
global: g
|
92
|
-
|
93
|
-
pointer: p
|
94
|
-
|
95
|
-
member: m
|
96
|
-
|
97
|
-
array: a
|
98
|
-
|
99
|
-
vector: vec
|
100
|
-
|
101
|
-
matrix: mat
|
102
|
-
|
103
|
-
index: id
|
104
|
-
|
105
|
-
count: cou
|
106
|
-
|
107
|
-
number: num
|
108
|
-
|
109
|
-
value: val
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
allocate: alloc,
|
114
|
-
|
115
|
-
buffer: buf,
|
116
|
-
|
117
|
-
current: cur,
|
118
|
-
|
119
|
-
dimension: dim,
|
120
|
-
|
121
|
-
direction: dire,
|
122
|
-
|
123
|
-
event: ev,
|
124
|
-
|
125
|
-
fragment: frag
|
126
|
-
|
127
|
-
height: hei,
|
128
|
-
|
129
|
-
inverse: inv,
|
130
|
-
|
131
|
-
location: loc,
|
132
|
-
|
133
|
-
medium: med,
|
134
|
-
|
135
|
-
multiply: mult,
|
136
|
-
|
137
|
-
normal : norm,
|
138
|
-
|
139
|
-
perspective: persp,
|
140
|
-
|
141
|
-
position: pos,
|
142
|
-
|
143
|
-
previous: pre,
|
144
|
-
|
145
|
-
projection: proj,
|
146
|
-
|
147
|
-
random: rand,
|
148
|
-
|
149
|
-
string: str,
|
150
|
-
|
151
|
-
target: tar,
|
152
|
-
|
153
|
-
texture: tex,
|
154
|
-
|
155
|
-
vertex: vert,
|
156
|
-
|
157
|
-
volume: vol,
|
158
|
-
|
159
|
-
width: wid,
|
160
|
-
|
161
|
-
win: win
|
162
|
-
|
163
|
-
*/
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
int main() {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
/* 初期化 */
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
/// GLFW を初期化する。
|
176
|
-
|
177
|
-
if (glfwInit() == GL_FALSE) {
|
178
|
-
|
179
|
-
// 初期化に失敗した。
|
180
|
-
|
181
|
-
std::cerr << "Can't Initialize GLFW" << std::endl;
|
182
|
-
|
183
|
-
};
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
// プログラム終了時の処理を登録する。
|
188
|
-
|
189
|
-
atexit(glfwTerminate);
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
//// OpenGL Version 3.2 Core Profile を選択する。
|
194
|
-
|
195
|
-
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
196
|
-
|
197
|
-
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
198
|
-
|
199
|
-
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
200
|
-
|
201
|
-
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
// ゲーム画面を構築するインスタンス生成。
|
206
|
-
|
207
|
-
// インスタンスへの参照を他クラスへ渡し、他クラスでもその処理を行えるようにする。
|
208
|
-
|
209
|
-
Window win;
|
210
|
-
|
211
|
-
Scene scene;
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
// 背景色を指定する。
|
216
|
-
|
217
|
-
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
// 背面カリングを有効にする。
|
222
|
-
|
223
|
-
glFrontFace(GL_CCW);
|
224
|
-
|
225
|
-
glCullFace(GL_BACK);
|
226
|
-
|
227
|
-
glEnable(GL_CULL_FACE);
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
// デプスバッファを有効にする。
|
232
|
-
|
233
|
-
glClearDepth(1.0);
|
234
|
-
|
235
|
-
glDepthFunc(GL_LESS);
|
236
|
-
|
237
|
-
glEnable(GL_DEPTH_TEST);
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
// ゲームループの変数初期化。
|
242
|
-
|
243
|
-
const std::chrono::milliseconds MS_PER_UPDATE(10);
|
244
|
-
|
245
|
-
std::chrono::milliseconds lag;
|
246
|
-
|
247
|
-
auto pre = std::chrono::system_clock::now();
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
// メインゲームループ。ゲームループでゲームを更新し、描画し続ける。
|
252
|
-
|
253
|
-
while (win.should_close(win.win()) == GL_FALSE) {
|
254
|
-
|
255
|
-
std::this_thread::sleep_for(std::chrono::seconds(1));
|
256
|
-
|
257
|
-
auto curr = std::chrono::system_clock::now();
|
258
|
-
|
259
|
-
// 処理に要した時間をミリ秒に変換。
|
260
|
-
|
261
|
-
auto elapsed =
|
262
|
-
|
263
|
-
std::chrono::duration_cast<std::chrono::milliseconds>(curr - pre);
|
264
|
-
|
265
|
-
pre = curr;
|
266
|
-
|
267
|
-
lag = lag + elapsed;
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
// 画面をクリア。
|
272
|
-
|
273
|
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
274
|
-
|
275
|
-
// 変換行列の初期化。
|
276
|
-
|
277
|
-
glLoadIdentity();
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
/* インプット */
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
// 現在のウィンドウの大きさを取得。
|
286
|
-
|
287
|
-
int wid, hei;
|
288
|
-
|
289
|
-
glfwGetFramebufferSize(win.win(), &wid, &hei);
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
// ESCキーで終了。
|
294
|
-
|
295
|
-
if (glfwGetKey(win.win(), GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
296
|
-
|
297
|
-
break;
|
298
|
-
|
299
|
-
};
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
while (lag >= MS_PER_UPDATE) {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
/* 更新 */
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
scene.update(win);
|
312
|
-
|
313
|
-
};
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
/* 描画 */
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
scene.render(win);
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
glViewport(0, 0, wid, hei);
|
326
|
-
|
327
|
-
lag -= MS_PER_UPDATE;
|
328
|
-
|
329
|
-
};
|
330
|
-
|
331
|
-
};
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
```
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
```c++
|
340
|
-
|
341
|
-
#pragma once
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
#include <GL/glew.h>
|
346
|
-
|
347
|
-
#include <GLFW/glfw3.h>
|
348
|
-
|
349
|
-
#include <iostream>
|
350
|
-
|
351
|
-
#include <vector>
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
// ウィンドウ関連の処理。
|
356
|
-
|
357
|
-
class Window {
|
358
|
-
|
359
|
-
// ウィンドウのポインタの入れ物。
|
360
|
-
|
361
|
-
GLFWwindow *win_;
|
362
|
-
|
363
|
-
// ウィンドウのサイズ。
|
364
|
-
|
365
|
-
std::vector<GLfloat> size_;
|
366
|
-
|
367
|
-
// 図形の正規化デバイス座標系上での位置。
|
368
|
-
|
369
|
-
std::vector<GLfloat> pos_;
|
370
|
-
|
371
|
-
// ワールド座標系に対するデバイス座標系の拡大率。
|
372
|
-
|
373
|
-
GLfloat scale_;
|
374
|
-
|
375
|
-
// キーボードの状態。
|
376
|
-
|
377
|
-
int key_status_;
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
public:
|
382
|
-
|
383
|
-
// コンストラクタ。
|
384
|
-
|
385
|
-
Window(int wid = 640, int hei = 480, const char *title = "MendelsEngine")
|
386
|
-
|
387
|
-
: win_(glfwCreateWindow(wid, hei, title, NULL, NULL)), scale_(100.0f),
|
388
|
-
|
389
|
-
key_status_(GLFW_RELEASE) {
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
// 作成したウィンドウをOpenGLの処理対象にする。
|
394
|
-
|
395
|
-
glfwMakeContextCurrent(win_);
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
// GLEW を初期化する。
|
400
|
-
|
401
|
-
glewExperimental = GL_TRUE;
|
402
|
-
|
403
|
-
if (glewInit() != GLEW_OK) {
|
404
|
-
|
405
|
-
// GLEW の初期化に失敗した。
|
406
|
-
|
407
|
-
std::cerr << "Can't initialize GLEW" << std::endl;
|
408
|
-
|
409
|
-
};
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
// 垂直同期のタイミングを待つ。
|
414
|
-
|
415
|
-
glfwSwapInterval(1);
|
416
|
-
|
417
|
-
// ウィンドウのサイズ変更時に呼び出す処理の登録。
|
418
|
-
|
419
|
-
glfwSetWindowSizeCallback(win_, &resize);
|
420
|
-
|
421
|
-
// マウスホイール操作時に呼び出す処理の登録。
|
422
|
-
|
423
|
-
glfwSetScrollCallback(win_, &wheel);
|
424
|
-
|
425
|
-
// キーボード操作時に呼び出す処理の登録。
|
426
|
-
|
427
|
-
glfwSetKeyCallback(win_, &keyboard);
|
428
|
-
|
429
|
-
// このインスタンスの this ポインタを記録しておく。
|
430
|
-
|
431
|
-
glfwSetWindowUserPointer(win_, this);
|
432
|
-
|
433
|
-
// 開いたウィンドウの初期設定。
|
434
|
-
|
435
|
-
resize(win_, wid, hei);
|
436
|
-
|
437
|
-
};
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
// デストラクタ。
|
442
|
-
|
443
|
-
virtual ~Window() { glfwDestroyWindow(win_); }
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
// メンバ関数。
|
448
|
-
|
449
|
-
int should_close(GLFWwindow *win) const;
|
450
|
-
|
451
|
-
void swap_buffers(GLFWwindow *win, int key_status);
|
452
|
-
|
453
|
-
// ウィンドウのサイズ変更時の処理。
|
454
|
-
|
455
|
-
static void resize(GLFWwindow *win, int wid, int hei){
|
456
|
-
|
457
|
-
// ウィンドウ全体をビューポートに設定する。
|
458
|
-
|
459
|
-
glViewport(0, 0, wid, hei);
|
460
|
-
|
461
|
-
// このインスタンスの this ポインタを得る。
|
462
|
-
|
463
|
-
Window *instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
464
|
-
|
465
|
-
if (instance != NULL) {
|
466
|
-
|
467
|
-
// 開いたウィンドウのサイズを保存する。
|
468
|
-
|
469
|
-
GLfloat wid0 = static_cast<GLfloat>(wid);
|
470
|
-
|
471
|
-
GLfloat hei0 = static_cast<GLfloat>(hei);
|
472
|
-
|
473
|
-
instance->size(0, wid0);
|
474
|
-
|
475
|
-
instance->size(1, hei0);
|
476
|
-
|
477
|
-
};
|
478
|
-
|
479
|
-
};
|
480
|
-
|
481
|
-
// マウスホイール操作時の処理。
|
482
|
-
|
483
|
-
static void wheel(GLFWwindow *win, double x, double y){
|
484
|
-
|
485
|
-
// このインスタンスの this ポインタを得る。
|
486
|
-
|
487
|
-
Window *const instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
488
|
-
|
489
|
-
if (instance != NULL) {
|
490
|
-
|
491
|
-
// ワールド座標系に対するデバイス座標系の拡大率を更新する。
|
492
|
-
|
493
|
-
GLfloat scale0 = instance->scale() + static_cast<GLfloat>(y);
|
494
|
-
|
495
|
-
instance->scale(scale0);
|
496
|
-
|
497
|
-
};
|
498
|
-
|
499
|
-
};
|
500
|
-
|
501
|
-
// キーボード操作時の処理。
|
502
|
-
|
503
|
-
static void keyboard(GLFWwindow *win, int action, int key = -1,
|
504
|
-
|
505
|
-
int scancode = -1, int mods = -1){
|
506
|
-
|
507
|
-
// このインスタンスの this ポインタを得る。
|
508
|
-
|
509
|
-
Window *const instance(static_cast<Window *>(glfwGetWindowUserPointer(win)));
|
510
|
-
|
511
|
-
if (instance != NULL) {
|
512
|
-
|
513
|
-
// キーの状態を保存する。
|
514
|
-
|
515
|
-
instance->key_status(action);
|
516
|
-
|
517
|
-
};
|
518
|
-
|
519
|
-
};
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
// アクセサ。
|
524
|
-
|
525
|
-
GLFWwindow *win() { return win_; };
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
std::vector<GLfloat> size() { return size_; };
|
530
|
-
|
531
|
-
GLfloat size(int i) { return size_[i]; };
|
532
|
-
|
533
|
-
void size(int i, GLfloat &glf) { size_[i] = glf; };
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
std::vector<GLfloat> pos() { return pos_; };
|
538
|
-
|
539
|
-
GLfloat pos(int i) { return pos_[i]; };
|
540
|
-
|
541
|
-
void pos(int i, GLfloat &glf) { pos_[i] = glf; };
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
GLfloat scale() { return scale_; };
|
546
|
-
|
547
|
-
void scale(GLfloat &glf) { scale_ = glf; };
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
int key_status() { return key_status_; };
|
552
|
-
|
553
|
-
void key_status(int &i) { key_status_ = i; };
|
554
|
-
|
555
|
-
};
|
556
|
-
|
557
|
-
```
|