2017-02-02 2 views
0

Ich habe stecken geblieben versuchen, dieses Ding herauszufinden. Ich versuche eine Skybox zu erstellen, aber aus irgendeinem Grund ist meine Cube Map immer schwarz. Wenn ich im Fragment-Shader einen Ausgabefarbwert wie vec4 (1.0f) einfüge, sehe ich, dass mein Würfel weiß wird. Was mich denken ließ, dass ich das Bild laden könnte, aber ich habe das überprüft und es lädt das Bild in Ordnung. Ich bin mir sicher, ich bin nur dumm und vermisse etwas.Cube Map schwarz mit Shadern C++

Erstellen von Cube Karte

glGenTextures(1, &cube_texture); 
    glBindTexture(GL_TEXTURE_CUBE_MAP, cube_texture); 
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 

    LoadCubeMapFace(posX, GL_TEXTURE_CUBE_MAP_POSITIVE_X); 
    LoadCubeMapFace(negX, GL_TEXTURE_CUBE_MAP_NEGATIVE_X); 
    LoadCubeMapFace(posY, GL_TEXTURE_CUBE_MAP_POSITIVE_Y); 
    LoadCubeMapFace(negY, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); 
    LoadCubeMapFace(posZ, GL_TEXTURE_CUBE_MAP_POSITIVE_Z); 
    LoadCubeMapFace(negZ, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); 

die Bilder Laden SDL_image mit

 void LoadCubeMapFace(const std::string& filename, GLenum face) 
     { 
      SDL_Surface *imageSurface = IMG_Load((TEXTURE_PATH + filename).c_str()); 
      if (!imageSurface){ 

       std::cout << "Can't Load image " << filename << " " << IMG_GetError(); 
       return; 
      } 

      GLint nOfColors = imageSurface->format->BytesPerPixel; 

      GLenum textureFormat = GL_RGB; 
      GLenum internalFormat = GL_RGB8; 

      if (nOfColors == 4)     // contains an alpha channel 
      { 
       if (imageSurface->format->Rmask == 0x000000ff){ 
        textureFormat = GL_RGBA; 
        internalFormat = GL_RGBA8; 
       } 
       else 
       { 
        textureFormat = GL_BGRA; 
        internalFormat = GL_RGBA8; 
       } 
      } 
      else if (nOfColors == 3)     // no alpha channel 
      { 
       if (imageSurface->format->Rmask == 0x000000ff){ 
        textureFormat = GL_RGB; 
        internalFormat = GL_RGB8; 
       } 
       else 
       { 
        textureFormat = GL_BGR; 
        internalFormat = GL_RGB8; 
       } 
      } 
      else 
      { 
       std::cout << "ERROR [SDL_Surface -> Texture]: Image is not True Color" << std::endl; 
       return; 
      } 
      glTexImage2D(face, 0, internalFormat, imageSurface->w, imageSurface->h, 0, textureFormat, GL_UNSIGNED_BYTE, imageSurface->pixels); 

      SDL_FreeSurface(imageSurface); 
     } 

Rendering Cubemap

glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_CUBE_MAP, texture->GetTextureMap()); 
    GLint texture_uniform = glGetUniformLocation(Skybox::shader->GetShaderProgram(), "cube_map"); 
    glUniform1i(texture_uniform, 0); 

VS & FS Shaders

#version 150 

    in vec3 vertex_position_model; 

    out vec3 the_uv; 

    uniform mat4 projection_matrix; 
    uniform mat4 view_matrix; 

    void main() 
    { 
     the_uv = vertex_position_model; 

     vec4 v = vec4(vertex_position_model, 1.0f); 
     gl_Position = projection_matrix * view_matrix * v; 
    } 


    #version 150 

    out vec4 FragColor; 

    in vec3 the_uv; 

    uniform samplerCube cube_map; 

    void main() 
    { 
     FragColor = texture(cube_map, the_uv); 
    } 

Antwort

0

Ich bin nicht sicher, was das Problem war, aber anscheinend die Bilder, die ich verwendete, funktionierten nicht richtig. Wenn Sie sie mit paint.NET öffnen und sie dann als 32-Bit-Tiefenbild speichern, scheint das Problem gelöst zu sein.