4
\$\begingroup\$

I made a very basic shader that works perfectly fine on Desktop, but when I try it with an AVD the sprite affected by the shader is not drawn. I have tried with WQVGA API 16 and Nexus S API 23. I have also tried putting this in my shaders but then it doesn't work on Desktop nor android :

#ifdef GL_ES
    "#version 300"
    precision mediump float;
#else
    "#version 130"
#endif

My vertex shader is simply a "passthrough" :

#version 130
attribute vec4 a_color;
attribute vec3 a_position;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;


varying vec4 v_color;
varying vec2 v_texCoord0;

void main() {
    v_color = a_color;
    v_texCoord0 = a_texCoord0;
    gl_Position =  u_projTrans * vec4(a_position, 1.0);
}

My Fragment Shader :

#version 130
precision mediump float;
varying vec4 v_color;
varying vec2 v_texCoord0;

uniform sampler2D u_sampler2D;
uniform vec4 color1;
uniform vec4 color2;

void main()
{
    vec4 actualColor = v_color * texture2D( u_sampler2D, v_texCoord0 );

    if(actualColor.g > actualColor.r)
        actualColor = color1;
    else if(actualColor.r > actualColor.g)
        actualColor = color2;


    gl_FragColor = actualColor;
}

Edit : I changed gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); in my fragment shader in order to test if a red rectangle would appear, but it failed. The red rectangle being the desktop version and on top being Android.

Fish does not appear

If it helps I also get this error in my Android console :

libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
emulator: Listening for console connections on port: 5554
emulator: Serial number of this emulator (for ADB): emulator-5554
emulator: emulator window was out of view and was recentered
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetUniformLocation:1628 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetUniformLocation:1628 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetUniformLocation:1628 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetUniformLocation:1628 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttribLocation:988 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttribLocation:988 error 0x501
distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttribLocation:988 error 0x501
\$\endgroup\$
  • 1
    \$\begingroup\$ Does it draw if you return a fixed color from the fragment shader? It may help to diagnose what in particular is wrong, for instance you may have a NaN in your texture coords somehow which may appear to not be drawing but is simply not visible. Same for drawing a sprite on a black background and the texture doesn't load it will sample as black. So, does gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); as the only expression in the fragment shader show a red sprite? \$\endgroup\$ – underscorediscovery Dec 16 '16 at 5:47
  • \$\begingroup\$ I added extra information in the edit, please check it out! \$\endgroup\$ – Cedric Martens Dec 16 '16 at 17:07
  • 5
    \$\begingroup\$ These errors by glGetUniformLocation and glGetAttribLocation mean the shader did not compile. You'll need to get the error messages from the shader compiler/linker. \$\endgroup\$ – Stephane Hockenhull Dec 18 '16 at 5:25
  • \$\begingroup\$ @CedricMartens what Stephane suggested. Are you checking the shader errors, and on android you ideally need to use android log function (printf won't really show up). There are examples on docs.gl here for compiling and here for linking to double check. \$\endgroup\$ – underscorediscovery Dec 19 '16 at 0:25
  • \$\begingroup\$ Are you sure the emulator supports #version 130? I think API 18 brought it into the mix, but I'd try #version 120 since it's a quick test. \$\endgroup\$ – Steve Tranby Dec 19 '16 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.