<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt3D Simple Example]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm using Qt5.8 and Win10. I'm working on a solution to display a pointcloud in a widget based application using qt3D.</p>
<p dir="auto">I'm new to Qt3D, but not to Qt framework.  I can't have a point displayed, and I think that I'm missing something somewhere.<br />
(For the following code, I'm just showing the important pieces).</p>
<p dir="auto">Is the following process the right one ? It seems right, but I obvisouly am missing something...</p>
<ol>
<li>
<p dir="auto">I create a very basic data sample</p>
<pre><code>// /////////////////////////////////////////////////////////////////////////
QByteArray *ba_positions = new QByteArray;
QDataStream stream_position(ba_positions, QIODevice::WriteOnly);
stream_position &lt;&lt; 10.0f &lt;&lt; 10.0f &lt;&lt; 10.0f;
stream_position &lt;&lt; 9.0f &lt;&lt; 9.0f &lt;&lt; 9.0f;
stream_position &lt;&lt; 8.0f &lt;&lt; 8.0f &lt;&lt; 8.0f;
stream_position &lt;&lt; 7.0f &lt;&lt; 7.0f &lt;&lt; 7.0f;
stream_position &lt;&lt; 6.0f &lt;&lt; 6.0f &lt;&lt; 6.0f;
stream_position &lt;&lt; 5.0f &lt;&lt; 5.0f &lt;&lt; 5.0f;
d-&gt;vertexBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer);
d-&gt;vertexBuffer-&gt;setData(*ba_positions);

// /////////////////////////////////////////////////////////////////////////
QByteArray *ba_colors = new QByteArray;
QDataStream stream_colors(ba_colors, QIODevice::WriteOnly);
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;
stream_colors &lt;&lt; 1.0f &lt;&lt; 1.0f &lt;&lt; 1.0f;

d-&gt;colorBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer);
d-&gt;colorBuffer-&gt;setData(*ba_colors);

// /////////////////////////////////////////////////////////////////////////
QByteArray *ba_normals = new QByteArray;
QDataStream stream_normals(ba_normals, QIODevice::WriteOnly);
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;
stream_normals &lt;&lt; 0.0f &lt;&lt; 1.0f &lt;&lt; 0.0f;

d-&gt;normalBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer);
d-&gt;normalBuffer-&gt;setData(*ba_normals);

</code></pre>
</li>
<li>
<p dir="auto">I create a geometry renderer</p>
</li>
</ol>
<pre><code>       	d-&gt;geometry = new Qt3DRender::QGeometry;
	d-&gt;renderer = new Qt3DRender::QGeometryRenderer;
        Qt3DRender::QAttribute  *attributePosition = new Qt3DRender::QAttribute(d-&gt;geometry);
	attributePosition-&gt;setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
	attributePosition-&gt;setDataType(Qt3DRender::QAttribute::Float);
	attributePosition-&gt;setDataSize(3);
	attributePosition-&gt;setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
	attributePosition-&gt;setBuffer(d-&gt;cloud-&gt;vertices());
	attributePosition-&gt;setByteOffset(0);
	attributePosition-&gt;setByteStride(0);
	attributePosition-&gt;setCount(6);

	Qt3DRender::QAttribute  *attributeColor = new Qt3DRender::QAttribute(d-&gt;geometry);
	attributeColor-&gt;setName(Qt3DRender::QAttribute::defaultColorAttributeName());
	attributeColor-&gt;setDataType(Qt3DRender::QAttribute::Float);
	attributeColor-&gt;setDataSize(3);
	attributeColor-&gt;setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
	attributeColor-&gt;setBuffer(d-&gt;cloud-&gt;colors());
	attributeColor-&gt;setByteStride(0);
	attributeColor-&gt;setByteOffset(0);
	attributeColor-&gt;setCount(6);

	Qt3DRender::QAttribute  *attributeNormal = new Qt3DRender::QAttribute(d-&gt;geometry);
	attributeNormal-&gt;setName(Qt3DRender::QAttribute::defaultNormalAttributeName());
	attributeNormal-&gt;setDataType(Qt3DRender::QAttribute::Float);
	attributeNormal-&gt;setDataSize(3);
	attributeNormal-&gt;setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
	attributeNormal-&gt;setBuffer(d-&gt;cloud-&gt;normals());
	attributeNormal-&gt;setByteStride(0);
	attributeNormal-&gt;setByteOffset(0);
	attributeNormal-&gt;setCount(6);

	d-&gt;geometry-&gt;addAttribute(attributePosition);
	d-&gt;geometry-&gt;addAttribute(attributeColor);
	d-&gt;geometry-&gt;addAttribute(attributeNormal);
	d-&gt;geometry-&gt;setBoundingVolumePositionAttribute(attributePosition);

	d-&gt;renderer = new Qt3DRender::QGeometryRenderer;
	d-&gt;renderer-&gt;setPrimitiveType(Qt3DRender::QGeometryRenderer::Points);
	d-&gt;renderer-&gt;setGeometry(d-&gt;geometry);
</code></pre>
<ol start="3">
<li>I create ascene to display my elements<pre><code>    //  Window //////////////////////////////////////////////////////////////////
d-&gt;window = new Qt3DExtras::Qt3DWindow;
    // d-&gt;window-&gt;defaultFrameGraph()-&gt;setClearColor(QColor(QRgb(0x332e2f)));
d-&gt;window-&gt;defaultFrameGraph()-&gt;setClearColor(QColor(QRgb(0x000000)));
d-&gt;windowContainer = QWidget::createWindowContainer(d-&gt;window);

// Root entity
d-&gt;rootEntity = new Qt3DCore::QEntity();

d-&gt;window-&gt;setRootEntity(d-&gt;rootEntity);
</code></pre>
</li>
</ol>
<pre><code>
4) I create my element
</code></pre>
<pre><code>    Qt3DCore::QEntity *cloudEntity = new Qt3DCore::QEntity(d-&gt;rootEntity);
cloudEntity-&gt;setParent(d-&gt;rootEntity); 
cloudEntity-&gt;addComponent(geometry-&gt;renderer());
</code></pre>
<pre><code>
--------------------------------------------------------
I have tried to add a material, and a transform to enhance my element : 

//	// Cloud Material //////////////////////////////////////////////////////////
	Qt3DCore::QEntity *cloudEntity = new Qt3DCore::QEntity(d-&gt;rootEntity);
	cloudEntity-&gt;setParent(d-&gt;rootEntity);

	Qt3DRender::QShaderProgram *shaderProgram = new Qt3DRender::QShaderProgram(cloudEntity);
	shaderProgram-&gt;setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource( QUrl("qrc:/shaders/shaders/pointcloud.frag")));
	shaderProgram-&gt;setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(QUrl("qrc:/shaders/shaders/pointcloud.vert")));

	Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass(cloudEntity);
	renderPass-&gt;setShaderProgram(shaderProgram);

	Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique(cloudEntity);
	technique-&gt;addRenderPass(renderPass);

	Qt3DRender::QEffect *effect = new Qt3DRender::QEffect(cloudEntity);
	effect-&gt;addTechnique(technique);

	Qt3DRender::QParameter *parameter = new Qt3DRender::QParameter("pointSize", 1.0);

	Qt3DRender::QMaterial *cloudMaterial = new Qt3DRender::QMaterial(cloudEntity);
	cloudMaterial-&gt;setEffect(effect);
	cloudMaterial-&gt;addParameter(parameter);

	// Cloud Transform /////////////////////////////////////////////////////////
	Qt3DCore::QTransform *cloudTransform = new Qt3DCore::QTransform(cloudEntity);
	cloudTransform-&gt;setScale(2);
	cloudTransform-&gt;setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), 25.0f));
	cloudTransform-&gt;setTranslation(QVector3D(5,4,0));

	// Cloud Entity ////////////////////////////////////////////////////////////
	cloudEntity-&gt;addComponent(cloudTransform);
	cloudEntity-&gt;addComponent(geometry-&gt;renderer());
	cloudEntity-&gt;addComponent(cloudMaterial);</code></pre>
]]></description><link>https://forum.qt.io/topic/76947/qt3d-simple-example</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 22:41:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/76947.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Mar 2017 15:18:06 GMT</pubDate><ttl>60</ttl></channel></rss>