- Home /
OpenGL does not work in the Android plugin
- Unity5.3.7f1 
- Nexus6(Android7) 
I expect the following code to made a texture on Android, and the texture was to be drawn in green, but in fact it was drawn in black. There is no runtime error. Where would be the problem?
C#
         AndroidJavaObject javaObject = new AndroidJavaObject ("com.example.myclass");
         AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         context  = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
 
         Texture2D texture = new Texture2D(640, 480, TextureFormat.ARGB32, false);
         gameObj.GetComponent<Renderer>().material.mainTexture = texture;
         var id = javaObject.Call<int>("getTexture");
         Debug.Log("texture pointer :" + id);
         var p = new IntPtr(id);
         Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 480, TextureFormat.ARGB32, false, true, p);
         texture.UpdateExternalTexture(nativeTexture.GetNativeTexturePtr());
Android(Java)
     public int getTexture(){
         Log.d(TAG, "getTexture called");
         GLES20.glEnable(GLES20.GL_TEXTURE_2D);
         int[] tmp = new int[1];  
         GLES20.glGenTextures(1, tmp, 0);
         int textureId = tmp[0];
         GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
         GLES20.glViewport(0,0,640,480);
 
         GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                 GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
         GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                 GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
         GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                 GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
         GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                 GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
 
         GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
         GLES20.glViewport(0,0,640,480);
         GLES20.glClearColor(0, 1, 0, 1); // green
         GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
         GLES20.glFlush();
         Log.d(TAG, "textureId is:" + textureId);
         return textureId;
     }
               Comment
              
 
               
              Answer by fcx1989 · Dec 12, 2018 at 06:26 AM
Maybe multithreaded rendering turned on. See: https://stackoverflow.com/questions/47779970/get-bitmap-to-unity-through-android-plugin-using-gles20/47781134#47781134
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                