質問編集履歴
6
文章を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,8 +12,9 @@
|
|
12
12
|
{
|
13
13
|
GLuint texture;
|
14
14
|
glGenTextures(1, &texture); //テクスチャIDの生成
|
15
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
15
16
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texture); // IDバインド
|
16
|
-
|
17
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
17
18
|
for (int i = 0; i < filePath.size(); i++)
|
18
19
|
{
|
19
20
|
glm::ivec2 size;
|
@@ -23,9 +24,9 @@
|
|
23
24
|
|
24
25
|
if (data != NULL)
|
25
26
|
{
|
26
|
-
|
27
|
+
|
27
28
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
28
|
-
|
29
|
+
|
29
30
|
stbi_image_free(data);
|
30
31
|
}
|
31
32
|
else
|
5
文章を修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Opengl glBindTexture()関数を実行すると画面が白
|
1
|
+
Opengl glBindTexture()関数でCUBE_MAPを実行すると画面が真っ白になる原因が知りたい。
|
body
CHANGED
File without changes
|
4
文章を修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Opengl
|
1
|
+
Opengl glBindTexture()関数を実行すると画面が白くなる原因が知りたい。
|
body
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
提示コードのですが下記の
|
1
|
+
提示コードのですが下記の`///`コメント部の関数を実行するとその後の出力画面が白くなるのですがこれは何が原因なのでしょか?
|
2
2
|
|
3
|
-
##### 確認したいこと
|
4
|
-
シェーダーを確認
|
5
|
-
画像ファイルの読み込みがキューブになっているか確認
|
6
3
|
|
7
4
|
|
8
|
-
|
9
5
|
参考サイト:[ https://learnopengl.com/Advanced-OpenGL/Cubemaps](https://learnopengl.com/Advanced-OpenGL/Cubemaps)
|
10
6
|
参考コード: [https://learnopengl.com/code_viewer_gh.php?code=src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp](https://learnopengl.com/code_viewer_gh.php?code=src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp)
|
11
7
|
|
@@ -27,7 +23,9 @@
|
|
27
23
|
|
28
24
|
if (data != NULL)
|
29
25
|
{
|
26
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
-
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
27
|
+
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
28
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
31
29
|
stbi_image_free(data);
|
32
30
|
}
|
33
31
|
else
|
3
文章を修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Opengl
|
1
|
+
Opengl GL_TEXTURE_CUBE_MAP_POSITIVE_X実行すると画面が白くなる原因が知りたい。
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
提示コードの
|
1
|
+
提示コードのですが下記の参考コード通り実装してもスカイボックスが表示されません。これはなぜでしょうか?現状は白い画面が表示されます。これは何が原因なのでしょうか?
|
2
2
|
|
3
3
|
##### 確認したいこと
|
4
4
|
シェーダーを確認
|
@@ -9,52 +9,6 @@
|
|
9
9
|
参考サイト:[ https://learnopengl.com/Advanced-OpenGL/Cubemaps](https://learnopengl.com/Advanced-OpenGL/Cubemaps)
|
10
10
|
参考コード: [https://learnopengl.com/code_viewer_gh.php?code=src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp](https://learnopengl.com/code_viewer_gh.php?code=src/4.advanced_opengl/6.1.cubemaps_skybox/cubemaps_skybox.cpp)
|
11
11
|
|
12
|
-
|
13
|
-
##### 描画ループ
|
14
|
-
```cpp
|
15
|
-
|
16
|
-
// ##################################### 描画 #####################################
|
17
|
-
void FrameWork::Camera::View(std::shared_ptr<Actor> actor)
|
18
|
-
{
|
19
|
-
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
20
|
-
glViewport(0, 0, windowContext->getSize().x, windowContext->getSize().y);
|
21
|
-
|
22
|
-
actor->Renderer_Depth(getViewPerspective());
|
23
|
-
|
24
|
-
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferFBO);
|
25
|
-
glViewport(0, 0, windowContext->getSize().x, windowContext->getSize().y);
|
26
|
-
|
27
|
-
glEnable(GL_DEPTH_TEST);
|
28
|
-
actor->Renderer(getViewPerspective());
|
29
|
-
|
30
|
-
glDisable(GL_DEPTH_TEST);
|
31
|
-
actor->Renderer_2D(getViewOrthographic());
|
32
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
-
glEnable(GL_DEPTH_TEST);
|
34
|
-
// draw skybox as last
|
35
|
-
glDepthFunc(GL_LEQUAL); // change depth function so depth test passes when values are equal to depth buffer's content
|
36
|
-
glDepthMask(GL_FALSE);
|
37
|
-
skyBoxShader->setEnable();
|
38
|
-
// skybox cube
|
39
|
-
glBindVertexArray(skyBoxVAO);
|
40
|
-
glBindBuffer(GL_ARRAY_BUFFER, skyBoxVBO);
|
41
|
-
|
42
|
-
skyBoxShader->setUniformSampler2D_CubeMap("skybox",0,skyBoxTexture);
|
43
|
-
skyBoxShader->setUniformMatrix4fv("uViewProjection", getViewPerspective());
|
44
|
-
|
45
|
-
glDrawArrays(GL_TRIANGLES, 0, 36);
|
46
|
-
glDepthMask(GL_TRUE);
|
47
|
-
skyBoxShader->setDisable();
|
48
|
-
glDepthFunc(GL_LESS); // set depth function back to default
|
49
|
-
|
50
|
-
glBindVertexArray(0);
|
51
|
-
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
52
|
-
|
53
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
-
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
55
|
-
}
|
56
|
-
```
|
57
|
-
|
58
12
|
##### 画像読み込み部
|
59
13
|
```
|
60
14
|
// ##################################### キューブマップテクスチャ 生成 #####################################
|
@@ -96,184 +50,4 @@
|
|
96
50
|
return texture;
|
97
51
|
}
|
98
52
|
|
99
|
-
|
100
|
-
```
|
101
|
-
|
102
|
-
##### 初期化部
|
103
|
-
```
|
104
|
-
|
105
|
-
float FrameWork::Camera::skyboxVertices[108] = {
|
106
|
-
// positions
|
107
|
-
-1.0f, 1.0f, -1.0f,
|
108
|
-
-1.0f, -1.0f, -1.0f,
|
109
|
-
1.0f, -1.0f, -1.0f,
|
110
|
-
1.0f, -1.0f, -1.0f,
|
111
|
-
1.0f, 1.0f, -1.0f,
|
112
|
-
-1.0f, 1.0f, -1.0f,
|
113
|
-
|
114
|
-
-1.0f, -1.0f, 1.0f,
|
115
|
-
-1.0f, -1.0f, -1.0f,
|
116
|
-
-1.0f, 1.0f, -1.0f,
|
117
|
-
-1.0f, 1.0f, -1.0f,
|
118
|
-
-1.0f, 1.0f, 1.0f,
|
119
|
-
-1.0f, -1.0f, 1.0f,
|
120
|
-
|
121
|
-
1.0f, -1.0f, -1.0f,
|
122
|
-
1.0f, -1.0f, 1.0f,
|
123
|
-
1.0f, 1.0f, 1.0f,
|
124
|
-
1.0f, 1.0f, 1.0f,
|
125
|
-
1.0f, 1.0f, -1.0f,
|
126
|
-
1.0f, -1.0f, -1.0f,
|
127
|
-
|
128
|
-
-1.0f, -1.0f, 1.0f,
|
129
|
-
-1.0f, 1.0f, 1.0f,
|
130
|
-
1.0f, 1.0f, 1.0f,
|
131
|
-
1.0f, 1.0f, 1.0f,
|
132
|
-
1.0f, -1.0f, 1.0f,
|
133
|
-
-1.0f, -1.0f, 1.0f,
|
134
|
-
|
135
|
-
-1.0f, 1.0f, -1.0f,
|
136
|
-
1.0f, 1.0f, -1.0f,
|
137
|
-
1.0f, 1.0f, 1.0f,
|
138
|
-
1.0f, 1.0f, 1.0f,
|
139
|
-
-1.0f, 1.0f, 1.0f,
|
140
|
-
-1.0f, 1.0f, -1.0f,
|
141
|
-
|
142
|
-
-1.0f, -1.0f, -1.0f,
|
143
|
-
-1.0f, -1.0f, 1.0f,
|
144
|
-
1.0f, -1.0f, -1.0f,
|
145
|
-
1.0f, -1.0f, -1.0f,
|
146
|
-
-1.0f, -1.0f, 1.0f,
|
147
|
-
1.0f, -1.0f, 1.0f
|
148
|
-
};
|
149
|
-
|
150
|
-
// ##################################### 初期化 #####################################
|
151
|
-
FrameWork::Camera::Camera()
|
152
|
-
{
|
153
|
-
//MSAA バッファ
|
154
|
-
glGenFramebuffers(1, &frameBufferFBO);
|
155
|
-
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferFBO);
|
156
|
-
glGenTextures(1, &frameBuffer);
|
157
|
-
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, frameBuffer);
|
158
|
-
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_RGB, windowContext->getSize().x, windowContext->getSize().y, GL_TRUE);
|
159
|
-
|
160
|
-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + frameBufferNumber, GL_TEXTURE_2D_MULTISAMPLE, frameBuffer, 0);
|
161
|
-
|
162
|
-
|
163
|
-
//レンダリングバッファ
|
164
|
-
glGenRenderbuffers(1, &rbo);
|
165
|
-
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
166
|
-
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 8, GL_DEPTH24_STENCIL8, windowContext->getSize().x, windowContext->getSize().y);
|
167
|
-
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
168
|
-
|
169
|
-
//MSAA アタッチ
|
170
|
-
GLuint attachment = GL_COLOR_ATTACHMENT0 + frameBufferNumber;
|
171
|
-
glDrawBuffers(1,&attachment);
|
172
|
-
|
173
|
-
|
174
|
-
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
175
|
-
{
|
176
|
-
std::cerr << "Framebuffer is not complete: 0x" << glCheckFramebufferStatus(GL_FRAMEBUFFER) << std::endl;
|
177
|
-
assert(0);
|
178
|
-
}
|
179
|
-
glBindFramebuffer(GL_FRAMEBUFFER,0);
|
180
|
-
|
181
|
-
|
182
|
-
//深度マップ
|
183
|
-
glGenFramebuffers(1, &depthMapFBO);
|
184
|
-
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
185
|
-
glGenTextures(1, &depthMap);
|
186
|
-
glBindTexture(GL_TEXTURE_2D, depthMap);
|
187
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowContext->getSize().x, windowContext->getSize().y, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
188
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
189
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
190
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
191
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
192
|
-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
|
193
|
-
|
194
|
-
//カラーバッファ
|
195
|
-
glGenFramebuffers(1, &colorBufferFBO);
|
196
|
-
glBindFramebuffer(GL_FRAMEBUFFER, colorBufferFBO);
|
197
|
-
glGenTextures(1, &colorBuffer);
|
198
|
-
glBindTexture(GL_TEXTURE_2D, colorBuffer);
|
199
|
-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, windowContext->getSize().x, windowContext->getSize().y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
200
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
201
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
202
|
-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + frameBufferNumber, GL_TEXTURE_2D, colorBuffer, 0); // we only need a color buffer
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
-
//スカイボックス
|
208
|
-
skyBoxShader = std::make_shared<FrameWork::Shader>();
|
209
|
-
|
210
|
-
glGenVertexArrays(1, &skyBoxVAO);
|
211
|
-
glGenBuffers(1, &skyBoxVBO);
|
212
|
-
|
213
|
-
skyBoxShader->Load("shader/SkyBox.vert", "shader/SkyBox.frag");
|
214
|
-
|
215
|
-
skyBoxShader->setEnable();
|
216
|
-
glBindVertexArray(skyBoxVAO);
|
217
|
-
glBindBuffer(GL_ARRAY_BUFFER, skyBoxVBO);
|
218
|
-
|
219
|
-
glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float) * 36, &skyboxVertices, GL_STATIC_DRAW);
|
220
|
-
|
221
|
-
GLuint attrib = skyBoxShader->getAttribLocation("vertexPosition");
|
222
|
-
glEnableVertexAttribArray(attrib);
|
223
|
-
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
224
|
-
skyBoxShader->setBindAttribLocation("vertexPosition");
|
225
|
-
|
226
|
-
skyBoxShader->setDisable();
|
227
|
-
glBindVertexArray(0);
|
228
|
-
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
234
|
-
position = glm::vec3(0,0,10); //座標
|
235
|
-
vecLook = glm::vec3(0,0,-1); //向き
|
236
|
-
|
237
|
-
setPosition(position);
|
238
|
-
setLook(vecLook);
|
239
|
-
|
240
|
-
frameBufferNumber += 1;
|
241
|
-
}
|
242
|
-
|
243
|
-
```
|
244
|
-
|
245
|
-
##### GLSL フラグメント
|
246
|
-
```
|
247
|
-
#version 420
|
248
|
-
|
249
|
-
out vec4 FragColor;
|
250
|
-
|
251
|
-
layout (location = 1) out vec3 TexCoords;
|
252
|
-
|
253
|
-
uniform samplerCube skybox;
|
254
|
-
|
255
|
-
void main()
|
256
|
-
{
|
257
|
-
FragColor = texture(skybox, TexCoords);
|
258
|
-
}
|
259
|
-
|
260
|
-
```
|
261
|
-
|
262
|
-
##### GLSL 頂点シェーダー
|
263
|
-
```
|
264
|
-
#version 420
|
265
|
-
|
266
|
-
layout (location = 0) in vec3 vertexPosition;
|
267
|
-
|
268
|
-
layout (location = 1) out vec3 TexCoords;
|
269
|
-
|
270
|
-
uniform mat4 uViewProjection;
|
271
|
-
|
272
|
-
void main()
|
273
|
-
{
|
274
|
-
TexCoords = vertexPosition;
|
275
|
-
vec4 pos = uViewProjection * vec4(vertexPosition, 1.0);
|
276
|
-
|
277
|
-
gl_Position = pos.xyww;
|
278
|
-
}
|
279
53
|
```
|
2
文章を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
提示コードの`///`コメント部ですが下記の参考コード通り実装してもスカイボックスが表示されません。これはなぜでしょうか?現状は白い画面が表示されます。
|
2
2
|
|
3
|
-
#####
|
3
|
+
##### 確認したいこと
|
4
4
|
シェーダーを確認
|
5
5
|
画像ファイルの読み込みがキューブになっているか確認
|
6
6
|
|
1
文章を修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -240,4 +240,40 @@
|
|
240
240
|
frameBufferNumber += 1;
|
241
241
|
}
|
242
242
|
|
243
|
+
```
|
244
|
+
|
245
|
+
##### GLSL フラグメント
|
246
|
+
```
|
247
|
+
#version 420
|
248
|
+
|
249
|
+
out vec4 FragColor;
|
250
|
+
|
251
|
+
layout (location = 1) out vec3 TexCoords;
|
252
|
+
|
253
|
+
uniform samplerCube skybox;
|
254
|
+
|
255
|
+
void main()
|
256
|
+
{
|
257
|
+
FragColor = texture(skybox, TexCoords);
|
258
|
+
}
|
259
|
+
|
260
|
+
```
|
261
|
+
|
262
|
+
##### GLSL 頂点シェーダー
|
263
|
+
```
|
264
|
+
#version 420
|
265
|
+
|
266
|
+
layout (location = 0) in vec3 vertexPosition;
|
267
|
+
|
268
|
+
layout (location = 1) out vec3 TexCoords;
|
269
|
+
|
270
|
+
uniform mat4 uViewProjection;
|
271
|
+
|
272
|
+
void main()
|
273
|
+
{
|
274
|
+
TexCoords = vertexPosition;
|
275
|
+
vec4 pos = uViewProjection * vec4(vertexPosition, 1.0);
|
276
|
+
|
277
|
+
gl_Position = pos.xyww;
|
278
|
+
}
|
243
279
|
```
|