'texture2D': the corresponding overloaded OpenGL ES2 Android (JAVA) function was not found

I was working on a project, and for this project I had to go through a book called "OpenGL ES 2 for Android: A Quick Start Guide." So when I got to texturing, I got an error:

'texture2D' : No matching overloaded function found

When I compile the shader. 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 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 empty, only the clear color I set.

+4
source share
1 answer
varying vec4 v_TextureCoordinates;
        ^^^^

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

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

... a vec4 coord.

v_TextureCoordinates, swizzle:

gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates.xy );
+6

Source: https://habr.com/ru/post/1545436/


All Articles