2014-11-11 2 views
-1

'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); 
    } 
} 
+0

그럼 "문제"는 무엇입니까? 너의 가정을 괴롭 히고 있니? Bluescreening? 또한 [MCVE] (http://stackoverflow.com/help/mcve)를 게시하십시오. – genpfault

+0

문제는 렌더링에서 모델이 회색으로 표시된다는 것입니다. 즉, samplerCube 텍스처에서 데이터를 가져 오지 않는 것과 같습니다. 나는 이것도 질문에 추가했다. MCVE도 만들 겠지만 시간이 좀 걸립니다. –

+0

제 생각에 이것은 텍스 코디의 문제입니다. 버텍스 속성 포인터를 설정하는 codę를 게시 하시겠습니까? 어쩌면 당신은 그들을 활성화하는 것을 잊었을까요? – Anonymous

답변

2

큐브 맵 텍스처가 텍스처 완성되지 않았습니다. 모든 6면은 큐브 맵 텍스처가 완성되도록 지정되어야합니다. 스펙에서 :

또한 다음 조건이 모두 true 인 경우 큐브 맵 텍스처가 큐브 완성입니다. [..] 큐브 맵을 구성하는 6 개의 텍스처 이미지 각각의 level_base 배열은 동일하고 양의 값을 갖습니다 , 정사각형 치수.

귀하의 코드가 NEGATIVE_X에 대한 이미지를 지정하지 않습니다

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 
}; 

이 테이블을 사용하여, NEGATIVE_Y에 대한 이미지가 두 번 지정되지만 NEGATIVE_X를 실종. 그것은해야한다 :

uint TARGETS[6] = 
{ 
    GL_TEXTURE_CUBE_MAP_POSITIVE_X, 
    GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 
    GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 
    GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 
    GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 
    GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 
}; 

대신 6 개 개의 목표를 열거, 당신은 또한 6 개 개의 목표를 해결하기 위해 범위 0..5에서 i에 대한 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i를 사용할 수 있습니다.

+1

나는 그것을 놓쳤다는 것을 믿을 수 없다. 나는 여러 번 보았다. 고마워요, 이제 모든 것이 작동 중입니다. –

+0

당신의 시야는 인상적입니다 :) – Anonymous