c++ - Error compiling fragment shader on GLSL 1.30 -
what wrong following fragment shader? compiles ok under glsl 4.0 fails on glsl 1.30.
this code:
// fragment shader "uniform sampler2d texture;\n" "uniform sampler1d cmap;\n" "uniform float minz;\n" "uniform float maxz;\n" "\n" "void main() {\n" " float height = texture2d(texture,gl_texcoord[0].st);\n" " float lum = (height-minz)/(maxz-minz);\n" " if (lum > 1.0) lum = 1.0;\n" " else if (lum < 0.0) lum = 0.0;\n" " gl_fragcolor = texture1d(cmap, lum);\n" "}"
these errors:
fragment glcompileshader "" failed fragment shader "" infolog: 0:7(2): error: initializer of type vec4 cannot assigned variable of type float 0:8(2): error: initializer of type vec4 cannot assigned variable of type float 0:9(6): error: operands relational operators must scalar , numeric 0:9(6): error: if-statement condition must scalar boolean 0:9(17): error: value of type float cannot assigned variable of type vec4 0:10(11): error: operands relational operators must scalar , numeric
well, error messages clear wrong:
0:7(2): error: initializer of type vec4 cannot assigned variable of type float ---- float height = texture2d(texture,gl_texcoord[0].st);
one cannot assign vec4 float. texture2d returns vec4, cannot assigned float height. solution: add swizzle operator when need 1 channel:
float height = texture2d(texture,gl_texcoord[0].st).r;
beside this, shader should not compile in glsl version > 140, since gl_texcoord
removed in 150. same goes texture2d
, texture1d
method got replaced texture
function in 150. specifying glsl version #version 400
?
Comments
Post a Comment