Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 0a1223a3e4bb8a61fd0c6bd9fadbd0af > files > 199

qtcanvas3d5-doc-5.12.2-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- quickitemtexture.qdoc -->
  <title>Qt Quick Item as Texture Example | Qt Canvas 3D (deprecated) 5.12.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtcanvas3d-index.html">Qt Canvas 3D (deprecated)</a></td><td ><a href="qtcanvas3d-examples.html">Qt Canvas 3D Examples</a></td><td >Qt Quick Item as Texture Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcanvas3d-index.html">Qt 5.12.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#using-qt-quick-item-as-a-texture">Using Qt Quick Item as a Texture</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Item as Texture Example</h1>
<span class="subtitle"></span>
<!-- $$$quickitemtexture-brief -->
<p>A simple cube with a Qt Quick item as a texture.</p>
<!-- @@@quickitemtexture -->
<!-- $$$quickitemtexture-description -->
<div class="descr"> <a name="details"></a>
<p>The Qt Quick Item as Texture example shows how to use other Qt Quick items as a texture source for Qt Canvas3D textures.</p>
<p class="centerAlign"><img src="images/quickitemtexture-example.png" alt="" /></p><a name="using-qt-quick-item-as-a-texture"></a>
<h2 id="using-qt-quick-item-as-a-texture">Using Qt Quick Item as a Texture</h2>
<p>First we create a Rectangle with a label that displays the current frame rate and rotation values of the cube:</p>
<pre class="qml">

  Rectangle {
      id: textureSource
      color: "lightgreen"
      width: 256
      height: 256
      border.color: "blue"
      border.width: 4
      layer.enabled: true
      layer.smooth: true
      Label {
          anchors.fill: parent
          anchors.margins: 16
          text: "X Rot:" + (canvas3d.xRotAnim | 0) + "\n"
              + "Y Rot:" + (canvas3d.yRotAnim | 0) + "\n"
              + "Z Rot:" + (canvas3d.zRotAnim | 0) + "\n"
              + "FPS:" + canvas3d.fps
          color: "red"
          font.pointSize: 26
          horizontalAlignment: Text.AlignLeft
          verticalAlignment: Text.AlignVCenter
      }
  }

</pre>
<p>We want to use the above Rectangle as the texture on our 3D cube. As a Rectangle item doesn't implement QQuickItem::textureProvider() by itself, we make it layered by setting the <code>layer.enabled</code> property to <code>true</code>.</p>
<p>To create a Canvas3DTexture out of our layered Rectangle, we create a <a href="qml-qtcanvas3d-canvas3dtextureprovider.html">QTCANVAS3D_texture_provider</a> extension and the texture in the <code>initializeGL()</code> function in our JavaScript implementation:</p>
<pre class="js">

  canvasTextureProvider = gl.getExtension("QTCANVAS3D_texture_provider");
  cubeTexture = canvasTextureProvider.createTextureFromSource(textureSourceItem);

</pre>
<p>Once the <code>cubeTexture</code> item is created, it can be used like any other texture item in the JavaScript.</p>
<p><b>Note: </b>The method of creating the texture from a Qt Quick item differs from how one would create texture from an HTML item in WebGL API. Textures created with <a href="qml-qtcanvas3d-canvas3dtextureprovider.html">QTCANVAS3D_texture_provider</a> extension support automatic live updates, without having to call textureImage2D each frame to re-upload fresh texture data from the item.</p><p>Files:</p>
<ul>
<li><a href="qtcanvas3d-quickitemtexture-main-cpp.html">quickitemtexture/main.cpp</a></li>
<li><a href="qtcanvas3d-quickitemtexture-qml-quickitemtexture-main-qml.html">quickitemtexture/qml/quickitemtexture/main.qml</a></li>
<li><a href="qtcanvas3d-quickitemtexture-qml-quickitemtexture-quickitemtexture-js.html">quickitemtexture/qml/quickitemtexture/quickitemtexture.js</a></li>
<li><a href="qtcanvas3d-quickitemtexture-quickitemtexture-pro.html">quickitemtexture/quickitemtexture.pro</a></li>
<li><a href="qtcanvas3d-quickitemtexture-quickitemtexture-qrc.html">quickitemtexture/quickitemtexture.qrc</a></li>
</ul>
</div>
<!-- @@@quickitemtexture -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>