'OpenGL 4.0 Shading Language Cookbook'을 읽었습니다. 하지만 큐브 맵 튜토리얼을 통해 벽에 부딪 혔습니다.OpenGL 4.0 큐브 맵 문제
내가 그리는 모델은 완전히 회색으로 표시됩니다. 마치 samplerCube 텍스처에서 어떤 데이터도 얻지 못하는 것처럼.
내 모든 코드가 올바른 것 같습니다. 다른 튜토리얼을 보았습니다. 똑같은 것입니다. 인텔 HD 그래픽 4000에 대한 책임은 있는지 모르겠지만 GL_ARB_texture_cube_map 확장이 있는지 확인했습니다.
파일에서 이미지를로드하는 데 DevIL 라이브러리를 사용하고 있습니다.이 이미지는 OpenGL에 데이터를 전송할 때 잘못 표시 될 수 있습니다.
파일에서 데이터를 가져 오는로드를 게시하고 있습니다. 모든 파일이 올바로로드됩니다. 또한 파이프 라인에 텍스처를 바인딩하는 드로잉 코드를 게시하고 있습니다. 그리고 정사각형과 조각 쉐이더를 경우에 따라 게시하고 있지만 꼭해야하는 것처럼 작동합니다.
아이디어가 있으십니까?
로드 코드
uint TARGETS[6] =
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
string EXTS[6] =
{
"posx",
"negx",
"posy",
"negy",
"posz",
"negz"
};
// Create & bind cubemap texture
glGenTextures(1, &cubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
for(int i = 0; i < 6; i++)
{
string file = "textures/cubemap_" + EXTS[i] + ".png";
uint image = ilGenImage();
// Load with DevIL
ilBindImage(image);
if(!ilLoadImage(file.c_str()))
{
cout << "ERROR: Failed to load image " << endl;
return false;
}
// Fetch info from DevIL
int width = ilGetInteger(IL_IMAGE_WIDTH);
int height = ilGetInteger(IL_IMAGE_HEIGHT);
uint format = ilGetInteger(IL_IMAGE_FORMAT);
uint type = ilGetInteger(IL_IMAGE_TYPE);
// Send data to OpenGL
glTexImage2D(
TARGETS[i],
0,
GL_RGBA,
width,
height,
0,
format,
type,
ilGetData());
// Error check
if(!ErrorCheck("Failed to bind a side of the cubemap!"))
return false;
// Get rid of DevIL data
ilDeleteImage(image);
}
// Parameters
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
그리기 코드
// Update
glfwPollEvents();
UpdateTime();
// Clear back buffer for new frame
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Bind shader
shader->Bind();
// Cubemap
shader->SetUniform("cubemapTexture", 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
// Bind model
if(model->Bind())
{
static float angle = 0;
angle += 25.0f * deltaTime;
// Matrices
mat4 world =
translate(vec3(0.0f, 0.0f, 0.0f)) *
rotateZ(angle * PI/180) *
rotateX(angle * PI/180) *
scale(vec3(1.0f, 1.0f, 1.0f));
mat4 view = ViewMatrix(
cameraPosition,
cameraTarget,
vec3(0.0f, 0.0f, 1.0f));
mat4 proj = ProjectionMatrix(
fov,
(float)windowX,
(float)windowY,
nearPlane,
farPlane);
// Uniforms
shader->SetUniform("uWorld", world);
shader->SetUniform("uView", view);
shader->SetUniform("uProj", proj);
shader->SetUniform("materialColor", vec3(0.5f, 0.5f, 0.5f));
shader->SetUniform("drawSkybox", false);
shader->SetUniform("world_cameraPosition", cameraPosition);
shader->SetUniform("reflectFactor", 0.5f);
// Draw
glDrawElements(GL_TRIANGLES, model->GetIndexCount(), GL_UNSIGNED_SHORT, NULL);
}
// Put the new image on the screen
glfwSwapBuffers(window);
버텍스 쉐이더
#version 400
layout(location=0) in vec3 vertex_position;
layout(location=1) in vec3 vertex_normal;
layout(location=2) in vec4 vertex_tangent;
layout(location=3) in vec2 vertex_texCoords;
out vec2 texCoords;
out vec3 reflectDir;
uniform mat4 uWorld;
uniform mat4 uView;
uniform mat4 uProj;
uniform bool drawSkybox;
uniform vec3 world_cameraPosition;
void main()
{
if(drawSkybox)
{
reflectDir = vertex_position;
}
else
{
vec3 world_pos = vec3(uWorld * vec4(vertex_position,1.0));
vec3 world_norm = vec3(uWorld * vec4(vertex_normal,0.0));
vec3 world_view = normalize(world_cameraPosition - world_pos);
reflectDir = reflect(-world_view, world_norm);
}
gl_Position = uProj * uView * uWorld * vec4(vertex_position,1.0);
texCoords = vertex_texCoords;
}
조각 쉐이더
#version 400
out vec4 fragColor;
in vec2 texCoords;
in vec3 reflectDir;
uniform samplerCube cubemapTexture;
uniform vec3 materialColor;
uniform bool drawSkybox;
uniform float reflectFactor;
void main()
{
vec3 color = texture(cubemapTexture, reflectDir).rgb;
if(drawSkybox)
{
fragColor = vec4(color, 1.0);
}
else
{
fragColor = vec4(mix(materialColor, color, reflectFactor), 1.0);
}
}
그럼 "문제"는 무엇입니까? 너의 가정을 괴롭 히고 있니? Bluescreening? 또한 [MCVE] (http://stackoverflow.com/help/mcve)를 게시하십시오. – genpfault
문제는 렌더링에서 모델이 회색으로 표시된다는 것입니다. 즉, samplerCube 텍스처에서 데이터를 가져 오지 않는 것과 같습니다. 나는 이것도 질문에 추가했다. MCVE도 만들 겠지만 시간이 좀 걸립니다. –
제 생각에 이것은 텍스 코디의 문제입니다. 버텍스 속성 포인터를 설정하는 codę를 게시 하시겠습니까? 어쩌면 당신은 그들을 활성화하는 것을 잊었을까요? – Anonymous