Hi,
I’m developing a game using shaders, and I can’t get it working on Android while it’s working fine on Windows 7.
To isolate the issue, I just deleted everything in my program that now looks like the HelloWorld sample.
I only have this in addition:
auto glProgram = cocos2d::GLProgram::createWithFilenames("SolidVertexShader.vsh", "SolidColorShader.fsh");
glProgram->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
glProgram->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD);
glProgram->link();
The error is show in the logCat of Android Studio when I use the link() function, not if I remove it.
The shaders are very simple:
vsh
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
psh
#ifdef GL_ES
precision lowp float;
#endif
varying vec2 v_texCoord;
uniform float u_color_red;
uniform float u_color_blue;
void main()
{
vec4 color = texture2D(CC_Texture0, v_texCoord);
gl_FragColor = vec4(u_color_red, 0, u_color_blue, color.a);
}
The log shows:
W/EGL_emulation? eglSurfaceAttrib not implemented
W/OpenGLRenderer? Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e7bb00, error=EGL_SUCCESS
...
D/cocos2d-x debug info? create rendererRecreatedListener for GLProgramState
D/cocos2d-x debug info? create rendererRecreatedListener for GLProgramState
D/cocos2d-x debug info? error: 0x502
D/cocos2d-x debug info? error: 0x502
D/cocos2d-x debug info? OpenGL error 0x0501 in jni/../../../../../cocos2d/cocos/renderer/CCTextureAtlas.cpp mapBuffers 312
W/EGL_emulation? eglSurfaceAttrib not implemented
W/OpenGLRenderer? Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6e2e2a0, error=EGL_SUCCESS
I tried on on an emulator and on a real device and it does not work anywhere.
I thought it could be related to some settings somewhere (maybe in Android Studio? who knows …), but everything I find does not seem to apply.
Please help I’m totally stuck
Thanks