2014-02-13 34 views
-1

上我使用LibGDX,有一个简单的片段着色器:LibGDX ShaderProgram未编译Android设备

#ifdef GL_ES 
#define mediump lowp 
precision mediump float; 
#else 
#define lowp 
#endif 

uniform sampler2D u_texture; 
uniform vec2 iResolution; 
uniform float iGlobalTime; 
uniform float glow; 


void main(void) 
{ 
vec2 uv = gl_FragCoord.xy/iResolution.xy; 
//uv.y = 1-uv.y; // THIS LINE EVOKES AN ERROR!!! 

uv.y += (sin((uv.x + (iGlobalTime * 0.2)) * 10.0) * 0.02)+0.02; 

vec4 color = vec4(glow,glow,glow,1);   
vec4 texColor = texture2D(u_texture, uv)*color; 
gl_FragColor = texColor; 
} 

它运作良好,在PC上,但Android设备上这个shader未编译。如果我评论该行(在示例中评论一行),一切都会好起来的。

我如何使用它:

mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0)); 
    mesh.setVertices(new float[] 
    {0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 1, 
    0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1, 
    -0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 0, 
    -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0});   
    mesh.setIndices(new short[] {0, 1, 2, 2, 3, 0}); 

    this.texture = texture; 
    shader = new ShaderProgram(Gdx.files.internal("shaders/default.vertex"), 
      Gdx.files.internal("shaders/glowwave.fragment")); 

Render方法:

texture.bind(); 
    shader.begin(); 

    shader.setUniformMatrix("u_worldView", localCam.projection); 
    shader.setUniformi("u_texture", 0); 
    shader.setUniformf("iGlobalTime", time); 
    shader.setUniformf("iResolution", new Vector2(Gdx.graphics.getWidth(),Gdx.graphics.getHeight()+15)); 
    shader.setUniformf("glow", glow); 
    mesh.render(shader, GL20.GL_TRIANGLES); 
    shader.end(); 

什么原因能是什么?在我看来,问题在于预处理器,虽然我可能是错的。

回答

1
ERROR: 0:17: '-' : Wrong operand types. No operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'float' (and there is no acceptable conversion) 
ERROR: 0:17: 'assign' : cannot convert from 'int' to 'float' 
ERROR: 2 compilation errors. No code generated. 

尝试:使用1.0而不是1个 uv.y = 1.0 - uv.y; //这条线是EVOKing一个错误!

+0

谢谢你快速回答!它帮助了我! – Nolesh

+0

你使用什么程序来查看错误? – Nolesh

+1

http://pastebin.com/KXSm3Pue here @Ares – jpm