LibGDX ShaderProgram未在Android设备上编译

时间:2014-02-13 15:35:46

标签: android libgdx shader fragment-shader

我正在使用LibGDX并有一个简单的片段着色器:

#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设备上,此着色器未编译。如果我评论该行(在示例中注释了一行),一切正常。

我如何使用它:

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"));

渲染方法:

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 个答案:

答案 0 :(得分: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; //这条线正在发生错误!