'texture2D' : No matching overloaded function found OpenGL ES2?

10,459
varying vec4 v_TextureCoordinates;
        ^^^^

There are exactly two texture2D() overloads in ES 2.0:

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

...neither of which accept a vec4 for coord.

Slice off the last two vector components of v_TextureCoordinates using a swizzle:

gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates.xy );
Share:
10,459
LessComplexity
Author by

LessComplexity

Updated on June 15, 2022

Comments

  • LessComplexity
    LessComplexity almost 2 years

    I was working on a project, and for that project I had to walk through a book called "OpenGL ES 2 For Android: A quick start guide". So when I got to texturing, I got the error of:

    'texture2D' : No matching overloaded function found
    

    When I compile the shader. The shader code:

    // 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;
    }
    

    I tried the same shaders for my project and for exactly the same code as in the book but it still gives me the same error when I compile the shader, and the viewport on the android device is blank, just the clear color I set is shown.