'texture2D' : No matching overloaded function found OpenGL ES2?
Asked Answered
T

1

9

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.

Teno answered 20/6, 2014 at 21:32 Comment(0)
P
11
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 );
Pimp answered 20/6, 2014 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.