I’m currently playing around with the native activity stuff and GLES 2.0 and I’m loading the shaders for GLES from the assets using the ndk.
This is the source of the simple shaders:
Vertex shader: simple.vsh
attribute vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
Fragment shader: simple.fsh
precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
This is the code that I’m using to load the shader files
AAsset *shaderAsset= AAssetManager_open(app->activity->assetManager, path, AASSET_MODE_BUFFER);
size_t length = AAsset_getLength(shaderAsset);
LOGI("Shader source size: %d\n", length);
char* buffer = (char*) malloc(length);
AAsset_read(shaderAsset, buffer, length);
LOGI("Shader source : %s\n", buffer);
AAsset_close(shaderAsset);
free(buffer);
When I run the application I see this in android logcat:
Shader source size: 71
07-22 13:23:52.683 11135 11146 I native-activity: Shader source : attribute vec4 vPosition;
07-22 13:23:52.683 11135 11146 I native-activity: void main()
07-22 13:23:52.683 11135 11146 I native-activity: {
07-22 13:23:52.683 11135 11146 I native-activity: gl_Position = vPosition;
07-22 13:23:52.683 11135 11146 I native-activity: }
07-22 13:23:52.683 11135 11146 I native-activity: sP
07-22 13:23:52.683 11135 11146 I native-activity: Shader source size: 86
07-22 13:23:52.683 11135 11146 I native-activity: Shader source : precision mediump float;
07-22 13:23:52.683 11135 11146 I native-activity: void main()
07-22 13:23:52.683 11135 11146 I native-activity: {
07-22 13:23:52.683 11135 11146 I native-activity: gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
07-22 13:23:52.683 11135 11146 I native-activity: }
07-22 13:23:52.683 11135 11146 I native-activity: fs`
Notice the “sP” and the “fs'” at the end of the files.
I’ve also added “nocompression” for the file extensions in my build xml file, just in case that is the problem, but hence the problem remains.
Does anyone have an idea what maybe causing this ?
Somehow the trailing zero does not get into the asset.
Try using