【问题标题】:OpenGL - Linking two textures doesn't workOpenGL - 链接两个纹理不起作用
【发布时间】:2014-11-01 08:34:45
【问题描述】:

我正在尝试将 FBO 的深度纹理和颜色纹理链接到 GLSL 着色器(4.0 版)

问题是,同时只有一个链接,很奇怪,因为其他纹理很好地链接在一起(例如:漫反射贴图、法线贴图和高光贴图)

这是我的绑定 RT 代码:

void RenderTexture::BindRead(GLuint locationColor,GLuint locationDepth,unsigned int unit,unsigned int dUnit)
{
    colorUnit = unit;
    this->depthUnit = dUnit;
    assert(unit >= 0 && unit <= 31);
    glActiveTexture(GL_TEXTURE0 + unit);
    glBindTexture(GL_TEXTURE_2D,m_rt);
    if (hasDepth)
    {
        assert(depthUnit >= 0 && depthUnit <= 31);
        glActiveTexture(GL_TEXTURE0 + dUnit);
        glBindTexture(GL_TEXTURE_2D,m_depth);
        glUniform1i(locationDepth,dUnit);
    }
    glUniform1i(locationColor,unit);
}

我真的不知道这里出了什么问题......

【问题讨论】:

  • 你怎么知道将纹理绑定到着色器不起作用?你有错误吗?
  • 不,我没有收到错误,两个 sampler2Ds 返回相同的值,(如果我先设置深度,那么它们都会有深度纹理)
  • 你能显示着色器吗?
  • #version 400 layout(location=0) out vec3 FragColor; in vec2 UV; uniform sampler2D rt0; uniform sampler2D d0; void main() { vec3 tex = texture(rt0,UV).xyz; vec3 depth = texture(d0,UV).xyz; FragColor = tex + depth; }

标签: c++ opengl textures


【解决方案1】:

终于,我找到了解决方案!问题是我在设置值之后绑定程序,它应该是之前,这也修复了我遇到的许多其他错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 2020-10-28
    • 2013-04-21
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多