2011-01-29 371 views
2

我与GLSL着色器的实验,但我得到一个有趣的错误,当我尝试从纹理获取数据来尝试一个简单的对比度增强算法。GLSL“的Texture2D”:没有匹配的重载函数发现的OpenGL ES2在iPhone

'texture2D' : no matching overloaded function found 

它发生在这个代码里,“final”是vec4变量来保存正在处理的颜色。这里的想法是将像素的颜色从周围推进(实验性的想法)。我会在有错误的代码中标记该行。

highp vec4 tex = texture2D(tex,vec2(texcoord.x+1.0,texcoord.y)); 
highp float total = tex.r + tex.g + tex.b; 
tex = texture2D(tex,vec2(texcoord.x-1.0,texcoord.y)); <----This one as well as the next similar lines 
total += tex.r + tex.g + tex.b; 
tex = texture2D(tex,vec2(texcoord.x,texcoord.y+1.0)); 
total += tex.r + tex.g + tex.b; 
tex = texture2D(tex,vec2(texcoord.x,texcoord.y-1.0)); 
total += tex.r + tex.g + tex.b; 
highp float di = 12.0; 
highp vec4 close_av = total/di; 
final = (final - close_av)*1.3+close_av; 

为什么不行呢?谢谢。

回答

6

假设tex最初在着色器源代码顶部声明为uniform sampler2D,它将被代码片段的第一行重新声明为局部变量,这隐藏了原始定义。更改任一变量以保持名称不同应解决您的编译问题。

+1

谢谢。下次累的时候我不会问问题。清醒时很容易发现这些错误。 :) – 2011-01-29 16:14:27

相关问题