View Full Version : Why is texture() returning a float and not vec4?

11-19-2011, 10:54 AM
I have a very simple GLSL shader that works fine on my desktop, but is crashing when I try and run it on my laptop. I have no idea why - my laptop seems to be expecting the texture() function to return a float.

The error is

Fragment shader failed to compile with the following errors:
ERROR: 0:12: 'texture' : no matching overloaded function found
ERROR: 0:12: '=' : cannot convert from 'const float' to '4-component vector of float'
ERROR: 2 compilation errors. No code generated.

The shader is:

uniform sampler2D u_tex0;
uniform float u_opacity;
uniform int u_type;

varying vec4 v_texCoord;

void main()
//Circle centered on origin
float dist = u_type == 0 ? v_texCoord.x : length(v_texCoord.xy);
vec2 src = vec2(dist, 0);
vec4 col = texture(u_tex0, src);
gl_FragColor = vec4(col.r, col.g, col.b, col.a * u_opacity);

11-19-2011, 11:22 AM
Looks like I need to specify texture2D(), and not just texture().

Alfonse Reinheart
11-19-2011, 12:41 PM
That's because you didn't specify a shader version. Your shader looks to be 1.10/1.20 style, rather than 1.30+ style. Either way, you should always specify a shader version.