仅显示灰色的 OpenGL 反射着色器

OpenGL Reflection shader showing only grey

我是 OpenGL 的新手,我一直在努力设置天空盒,并最终修复了它,感谢这里的一些帮助,但现在我尝试通过编辑一些我来设置反射着色器'我发现(所以球体将具有基于我的天空盒的立方体贴图的基本反射效果)不会显示任何颜色,而是灰色,如图所示。 http://i.imgur.com/Th56Phg.png

我没有找到答案,这是我的着色器代码:

顶点着色器

#version 330 core

attribute vec3 position;
attribute vec2 texCoord;
attribute vec3 normal;


out vec3 Normal;
out vec3 Position;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

uniform mat4 transform;

void main()
{
    gl_Position = transform * vec4(position, 1.0);
    Normal = mat3(transpose(inverse(model))) * normal;
    Position = vec3(model * vec4(position, 1.0f));
}  

片段着色器

#version 330 core
in vec3 Normal;
in vec3 Position;
out vec4 color;

uniform vec3 cameraPos;
uniform samplerCube skybox;

void main()
{             
    vec3 I = normalize(Position - cameraPos);
    vec3 R = reflect(I, normalize(Normal));
    color = texture(skybox, R);
}

最后这是我的用法:

glm::mat4 model;
        glm::mat4 view = camera.GetViewProjection();
        glm::mat4 projection = glm::perspective(70.0f, (float)1600 / (float)1200, 0.1f, 1000.0f);
        glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "model"), 1, GL_FALSE, glm::value_ptr(model));
        glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "view"), 1, GL_FALSE, glm::value_ptr(view));
        glUniformMatrix4fv(glGetUniformLocation(refShader.getProg(), "projection"), 1, GL_FALSE, glm::value_ptr(projection));
        glUniform3f(glGetUniformLocation(refShader.getProg(), "cameraPos"), camera.getPos().x, camera.getPos().y, camera.getPos().z);

        glActiveTexture(GL_TEXTURE3); 
        glUniform1i(glGetUniformLocation(refShader.getProg(), "skybox"), 3);

        shader.Bind();
        texture.Bind(0);
        shader.Update(transformCube, camera);
        cubeMesh.Draw();

        glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTexture);
        refShader.Bind();
        refShader.Update(transform, camera);
        sphereMesh.Draw();

这个操作顺序是错误的:

glActiveTexture(GL_TEXTURE3); 
glUniform1i(glGetUniformLocation(refShader.getProg(), "skybox"), 3);

shader.Bind();

制服在 GL 中每个程序 状态,glUniform*() 调用总是影响程序当前使用的制服.你好像在程序绑定之前尝试设置这个uniform,所以会失败,那个程序里面的uniform还是会停留在默认值0。