1

I'm trying to draw a triangle in qt6 3d, but i got this error in console... Notice that in my project i'm drawing other objects using the classic mesh classes from Qt and everything works perfect..

Failed to create input layout: Error 0x80070057: The parameter is incorrect. Qt3D.Renderer.RHI.Backend: Failed to build graphics pipeline: Creation Failed

This is the code i'm using:

QVector3D vertex1(0.0f, 0.0f, 0.0f);
QVector3D vertex2(1.0f, 0.0f, 0.0f);
QVector3D vertex3(0.0f, 1.0f, 0.0f);

Qt3DCore::QEntity* m_triangleObject = new Qt3DCore::QEntity(m_sharedSceneRoot);
Qt3DCore::QTransform* transform = new Qt3DCore::QTransform();
Qt3DCore::QGeometry* geometry = new Qt3DCore::QGeometry(m_triangleObject);
Qt3DCore::QBuffer* vertexDataBuffer = new Qt3DCore::QBuffer(geometry);
Qt3DCore::QAttribute* positionAttribute = new Qt3DCore::QAttribute(geometry);
Qt3DExtras::QPhongMaterial* material = new Qt3DExtras::QPhongMaterial();
material->setDiffuse(QColor("#686A63"));
Qt3DRender::QGeometryRenderer* geometryRenderer = new Qt3DRender::QGeometryRenderer();

QByteArray vertexBufferData;
vertexBufferData.resize(3 * sizeof(QVector3D));
QVector3D* positions = reinterpret_cast<QVector3D*>(vertexBufferData.data());
positions[0] = vertex1;
positions[1] = vertex2;
positions[2] = vertex3;
vertexDataBuffer->setData(vertexBufferData);

positionAttribute->setName(Qt3DCore::QAttribute::defaultPositionAttributeName());
positionAttribute->setAttributeType(Qt3DCore::QAttribute::VertexAttribute);
positionAttribute->setBuffer(vertexDataBuffer);
positionAttribute->setVertexBaseType(Qt3DCore::QAttribute::Float);
positionAttribute->setVertexSize(3);
positionAttribute->setCount(3);
positionAttribute->setByteOffset(0);
positionAttribute->setByteStride(sizeof(QVector3D));

geometry->addAttribute(positionAttribute);
geometryRenderer->setGeometry(geometry);
geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);

transform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));

m_triangleObject->addComponent(geometryRenderer);
m_triangleObject->addComponent(material);
m_triangleObject->addComponent(transform);

as i noticed, if i comment the material property, i don't get the error anymore but the triangle still are not displayed.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
Razvan B
  • 11
  • 2
  • Are you using MacOS? It's possible that metal (the underlying graphics library) does not support rasterised lines. This is because of a change to Qt6, since they are switching to RHI and MacOS deprecated OpenGL. – HarryP2023 Jun 29 '23 at 12:16

1 Answers1

0

your code lacks indexAttribute. Its an attribute that holds a group of three vertices for each triangle-face of your mesh.

QByteArray indexBytes;
indexBytes.resize(indexSize * sizeof(unsigned int));
unsigned int *indices = reinterpret_cast<unsigned int*>(indexBytes.data());
*indices ++= 0;
*indices ++= 1;
*indices ++= 2;

auto *indexBuffer = new Qt3DCore::QBuffer(geometry);
indexBuffer->setData(indexBytes);

auto *indexAttribute = new Qt3DCore::QAttribute(geometry);
indexAttribute->setVertexBaseType(Qt3DCore::QAttribute::UnsignedInt);
indexAttribute->setAttributeType(Qt3DCore::QAttribute::IndexAttribute);
indexAttribute->setBuffer(indexBuffer);
indexAttribute->setCount(3);
geometry->addAttribute(indexAttribute);
Nome
  • 11
  • 3