Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by gmmsh · Feb 20, 2017 at 09:40 AM · androidpluginopengl

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

No OpenGL Context in Unity above 2017.1.2f1 0 Answers

Opengl plugin for Android 0 Answers

Android OpenGL error in Unity 5 but not in Unity 4.6 0 Answers

GL_LUMINANCE format for texture uploads in Android plugin 0 Answers

How to make unity order draw over google Maps v2 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges