Skybox 正在覆盖模型

问题描述

我制作了以太阳为中心,行星围绕着他旋转的太阳系。我想添加天空盒,它添加正确,但我看不到我的行星。

添加天空盒之前:

enter image description here

添加天空盒后:

enter image description here

主天空盒代码

    // skyBox VAO
unsigned int skyBoxVAO,skyBoxVBO;
glGenVertexArrays(1,&skyBoxVAO);
glGenBuffers(1,&skyBoxVBO);
glBindVertexArray(skyBoxVAO);
glBindBuffer(GL_ARRAY_BUFFER,skyBoxVBO);
glBufferData(GL_ARRAY_BUFFER,sizeof(skyBoxVertices),&skyBoxVertices,GL_STATIC_DRAW);
glEnabLevertexAttribArray(0);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3 * sizeof(float),(void*)0);

vector<std::string> faces
{
    "res/textures/skyBox/right.png","res/textures/skyBox/left.png","res/textures/skyBox/top.png","res/textures/skyBox/bot.png","res/textures/skyBox/front.png","res/textures/skyBox/back.png"
};
unsigned int cubemapTexture = loadCubemap(faces);

窗口天空盒代码

        // draw skyBox as last
    glDepthFunc(GL_LEQUAL);  // change depth function so depth test passes when values are equal to depth buffer's content
    skyBoxShader.use();
    view = glm::mat4(glm::mat3(camera.GetViewMatrix())); // remove translation from the view matrix
    skyBoxShader.setMat4("view",view);
    skyBoxShader.setMat4("projection",projection);

            // skyBox cube
    glBindVertexArray(skyBoxVAO);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_CUBE_MAP,cubemapTexture);
    glDrawArrays(GL_TRIANGLES,36);
    glBindVertexArray(0);
    glDepthFunc(GL_LESS); // set depth function back to default

顶点着色器和片段着色器:

#version 330 core
layout (location = 0) in vec3 aPos;

out vec3 TexCoords;

uniform mat4 projection;
uniform mat4 view;

void main()
{
    TexCoords = aPos;
    vec4 pos = projection * view * vec4(aPos,1.0);
    gl_Position = projection * view * vec4(aPos,1.0);
}  

#version 330 core
out vec4 FragColor;

in vec3 TexCoords;

uniform samplerCube skyBox;

void main()
{    
    FragColor = texture(skyBox,TexCoords);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)