Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: load shader file from assets on android using AssetManager ?

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    5

    load shader file from assets on android using AssetManager ?

    hi, i try to load my shader file from assets using ndk, all work fine but final char array contain random sybols at end, and the compiler can't copile it, there is my function :

    Code :
    const char* getShaderSource(const char* src)
    {
    	AAsset* shaderAsset = AAssetManager_open(mgr,src, AASSET_MODE_UNKNOWN);
     
    	if (mgr == NULL) {
    		LOGE("mgr is null");
    	}
     
    	size_t length = AAsset_getLength(shaderAsset);
     
    	LOGI("Shader source size: %d\n", length);
     
     
    	char* buffer = (char*) malloc(sizeof(char)*length);
     
    	AAsset_read(shaderAsset, buffer, length);
     
    	LOGI("buffer source : %s\n", buffer);
     
    	AAsset_close(shaderAsset);
     
    	return (buffer);
     
    }

    can you help me please.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    602
    Since this isn't an OpenGL question, you probably have a better chance of getting an answer on an ndk (android?) development forum.
    Without knowing anything about these functions my guess would be the shader string is not '\0' terminated. You should allocate the buffer one byte larger than length and write '\0' into the last position to get a valid C string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •