Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by sriram4contact · Feb 05, 2021 at 10:14 PM · cameracanvaswebglrendertexturehtml5

Need to send Secondary camera render from unity webgl to HTML5 canvas

I am trying to write a code to send data from Unity Webgl to HTML5 canvas. I wasnt to capture the camera renderTexture and send it to the HTML5 where I can show it on a canvas. Note: This camera is additional camera apart from the main camera. I want to use this video feed to be displayed on a canvas.

I have been struggling to get it right. I followed the instructions given in https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

But still I find it hard as there is a warning saying, "VM107926:1 WebGL: INVALID_OPERATION: bindTexture: object does not belong to this context" And it is not displaying anything.

Could you please help me find a solution.

jslib -

    BindWebGLTexture: function (texture) {
     console.log("start rendering second camera");
     const canvas = document.querySelector("#secondCamera");
       // Initialize the GL context
       var GLctx = canvas.getContext("webgl");
       
       console.log("rendering second camera");
 
     //GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
     GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
     
     console.log("finished rendering second camera");
     check2 = GL.textures[texture];
   },


c# -

 [DllImport("__Internal")]
 private static extern void BindWebGLTexture(int texture);
     Texture2D texture1 = getCameraTexture();
     BindWebGLTexture((int)texture1.GetNativeTexturePtr());

 Texture2D getCameraTexture()
     {
 
         return toTexture2D(CamTexture);
     }
 
 
     Texture2D toTexture2D(RenderTexture rTex)
     {
         Texture2D tex = new Texture2D(CamTexture.width, CamTexture.height, TextureFormat.RGB24, false);
         RenderTexture.active = rTex;
         tex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0);
         tex.Apply();
         return tex;
     }


Unity - alt text

CamTexture = new render texture;

HTML:

 <!DOCTYPE html>
 <html lang="en-us">
   <head>
     <meta charset="utf-8">
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <title>Unity WebGL Player | New Unity Project (1)</title>
     <link rel="shortcut icon" href="/static/assets/robotarm2/TemplateData/favicon.ico">
     <link rel="stylesheet" href="/static/assets/robotarm2/TemplateData/style.css">
     <script src="/static/assets/robotarm2/TemplateData/UnityProgress.js"></script>
     <script src="/static/assets/robotarm2/Build/UnityLoader.js"></script>
     <script>
       //var unityInstance = UnityLoader.instantiate("unityContainer", "/static/assets/robotarm2/Build/Build.json", {onProgress: UnityProgress});
   var unityInstance = UnityLoader.instantiate("unityContainer", "/static/assets/robotarm2/Build/Build.json", {
     Module: {
         "webglContextAttributes": {"preserveDrawingBuffer": true},
     }
 });
     </script>
   </head>
   <body>
     <div class="webgl-content">
       <div id="unityContainer" style="width: 960px; height: 600px"></div>
       
     </div>
     <canvas id="secondCamera" style="position:absolute;top:800px" width="100px" height="100px"></canvas>
   </body>
 </html>

I dont get any errors but still I am not able to understand whats wrong or if I am missing something.

Please help me to solve this challenge.

ewre.jpg (83.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

182 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WebGL camera doesn't go past screen bounds 0 Answers

How to get pixeldata from graphics.drawmesh? 0 Answers

Help with Raycast on Render Texture 0 Answers

Render to RenderTexture and Screen both 1 Answer

in webgl , how to change #canvas property? 0 Answers


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