【问题标题】:'texture2D' : No matching overloaded function found OpenGL ES2?'texture2D':没有找到匹配的重载函数 OpenGL ES2?
【发布时间】:2014-08-11 17:24:40
【问题描述】:

我正在从事一个项目,对于该项目,我必须阅读一本名为“OpenGL ES 2 For Android:快速入门指南”的书。 所以当我开始纹理时,我得到了以下错误:

'texture2D' : No matching overloaded function found

当我编译着色器时。 着色器代码:

// Fragment shader
precision mediump float;

uniform sampler2D u_TextureUnit;
varying vec4 v_TextureCoordinates;

void main()
{
    gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates);
}

// Vertex shader
uniform mat4 u_Matrix;
attribute vec4 a_Position;
attribute vec4 a_TextureCoordinates;

varying vec4 v_TextureCoordinates;

void main()
{
    gl_Position = u_Matrix * a_Position;
    v_TextureCoordinates = a_TextureCoordinates;
}

我为我的项目尝试了相同的着色器,并使用了与书中完全相同的代码,但是当我编译着色器时它仍然给我同样的错误,并且 android 设备上的视口是空白的,只是我的清晰颜色设置显示。

【问题讨论】:

    标签: java android opengl-es texture2d


    【解决方案1】:
    varying vec4 v_TextureCoordinates;
            ^^^^
    

    在 ES 2.0 中有两个 texture2D() 重载:

    vec4 texture2D(sampler2D sampler, vec2 coord)
    vec4 texture2D(sampler2D sampler, vec2 coord, float bias)
    

    ...对于coord,两者都不接受vec4

    使用 swizzle 切掉 v_TextureCoordinates 的最后两个向量分量:

    gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates.xy );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2020-09-22
      • 2018-04-30
      • 2018-08-01
      相关资源
      最近更新 更多