# Is it possible to use canvas as GUI？

**URL:** <https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269>\
**Category:** Questions\
**Created:** [April 12, 2022, 1:39am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269 "2022-04-12T01:39:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZoeLeee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zoeleee/32/20340_2.png) [@ZoeLeee](https://forum.babylonjs.com/u/ZoeLeee)\
**Post date:** [April 12, 2022, 1:39am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/1 "2022-04-12T01:39:35Z")

</div>

I want to draw the canvas generated by a chart library such as echart or highcharts as a gui.  
Currently, I use the `toDataURL` method, but the original animation and other dynamic performance of the canvas will be lost. The way I think of at the moment is to use DynamicTexture, but I hope to have the effect of gui. Another way is to create a canvas dedicated to drawing these charts, or a VideoTexture.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [April 12, 2022, 12:45pm UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/2 "2022-04-12T12:45:30Z")

</div>

Hello! It is possible to do that easily with DynamicTexture, you can get the context of the canvas behind it and do anything that the Canvas API supports 🙂 Here’s a simple example of an animated canvas being used as DynamicTexture: [Dynamic canvas | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#3K0UBR)

In fact, that’s exactly how our GUI system works. 🙂

---

<div class="post-metadata">

**Author:** ![ZoeLeee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zoeleee/32/20340_2.png) [@ZoeLeee](https://forum.babylonjs.com/u/ZoeLeee)\
**Post date:** [April 13, 2022, 12:49am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/3 "2022-04-13T00:49:54Z")

</div>

`Dynamic Texture` is powerful, but I want the effect to be like a 2d gui, not affected by the camera. I know it’s possible to counteract the camera in code, but it would be better if there was a container like `Layer`.Or can I customize `AdvanceDynamicTexture`?

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [April 13, 2022, 3:56am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/4 "2022-04-13T03:56:32Z")

</div>

You can run another 2D engine at the same time on the same canvas - either on top or behind the babylonJS scene:  
[Babylon.js and Pixi.js | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/extensions/Babylon.js+ExternalLibraries/BabylonJS_and_PixiJS)

I have a Pixi v5 on top demo, which is needs to be fixed!  
[Integrations - PixiJS v5 ⋅ Storybook (brianzinn.github.io)](https://brianzinn.github.io/react-babylonjs/?path=/story/integrations--pixi-story)

---

<div class="post-metadata">

**Author:** ![ZoeLeee](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zoeleee/32/20340_2.png) [@ZoeLeee](https://forum.babylonjs.com/u/ZoeLeee)\
**Post date:** [April 13, 2022, 8:01am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/6 "2022-04-13T08:01:43Z")

</div>

I implemented `Video` gui and `Canvas` gui based on `Image` gui as the current solution, haven’t tested the performance. If there is a problem, try other solutions.  
My code:

> <https://gist.github.com/ZoeLeee/f4c58be0765fab64bc6821e15c82a6db>

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [May 25, 2022, 10:47am UTC](https://forum.babylonjs.com/t/is-it-possible-to-use-canvas-as-gui/29269/7 "2022-05-25T10:47:24Z")

</div>

Hey there just checking in, was your question answered? @ZoeLeee
