5
  1. Listed below is a simple test application. If to run this application, appears message "[Qt3DRender::GLTexture] No QTextureData generated from Texture Generator yet. Texture will be invalid for this frame", and on exit - the application crashes. What is the mistake of creating QText2DEntity? If to comment the marked fragment, then there will be no problems.

  2. How to attach QText2DEntity to camera (or screen)? I need to make that when moving the camera QText2DEntity remained always at fixed place.

main.cpp

#include <QGuiApplication>
#include <Qt3DCore/QEntity>
#include <Qt3DCore/QTransform>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QText2DEntity>
#include <Qt3DExtras/QFirstPersonCameraController>
#include <Qt3DRender/QCamera>

int main(int argc, char *argv[])
{
    QGuiApplication application(argc, argv);
    Qt3DExtras::Qt3DWindow window;

    auto scene = new Qt3DCore::QEntity;
    window.setRootEntity(scene);

    auto sphere = new Qt3DCore::QEntity(scene);

    auto transform = new Qt3DCore::QTransform;
    transform->setTranslation(QVector3D(0.0f, 0.0f, -10.0f));

    auto material = new Qt3DExtras::QPhongMaterial;
    material->setAmbient(QColor(245, 245, 245));
    material->setDiffuse(QColor(125, 125, 125));
    material->setSpecular(QColor(215, 215, 215));

    auto spheremesh = new Qt3DExtras::QSphereMesh;
    spheremesh->setRadius(15.0);
    spheremesh->setSlices(32);
    spheremesh->setRings(32);

    sphere->addComponent(transform);
    sphere->addComponent(material);
    sphere->addComponent(spheremesh);

    // QText2DEntity
    auto text2D = new Qt3DExtras::QText2DEntity(scene);
    text2D->setFont(QFont("monospace",5));
    text2D->setHeight(10.0);
    text2D->setWidth(20.0);
    text2D->setText("Test");
    text2D->setColor(Qt::yellow);

    auto text2dTransform = new Qt3DCore::QTransform;
    text2dTransform->setTranslation(QVector3D(-10.0f, 0.0f, 50.0f));
    text2D->addComponent(text2dTransform);
    //

    auto camera = window.camera();
    camera->lens()->setPerspectiveProjection(60.0f, static_cast<float>(window.width()) / window.height(), 0.1f, 1000.0f);
    camera->setPosition(QVector3D(0.0f, 0.0f, 100.0f));
    camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));

    auto camController = new Qt3DExtras::QFirstPersonCameraController(scene);
    camController->setCamera(camera);

    window.show();
    return application.exec();
}

test.pro

QT       += core 3dlogic 3dextras 3dinput

CONFIG += c++17

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
    main.cpp

HEADERS +=

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

code tested at Qt 5.13.1

avttrue
  • 387
  • 2
  • 12
  • It seems that the code is missing adding `text2D` as component to the other entity. Either `sphere` or `scene` should have `text2D` as component, I guess. – Alexander V Oct 17 '19 at 14:54
  • @AlexanderV QText2DEntity is Entity, this is not Component. As I understood: [https://doc.qt.io/QT-5/qt3dextras-qtext2dentity.html#details](https://doc.qt.io/QT-5/qt3dextras-qtext2dentity.html#details) – avttrue Oct 17 '19 at 18:06
  • 1
    I used the other text entity type QExtrudedTextMesh in our code exactly by putting it inside the other root entity which is part of a scene Scene3D or QScene3D which appear to be missing as well. @avttrue, like your avatar, Гагарин. – Alexander V Oct 17 '19 at 20:17
  • @AlexanderV Thanks for the idea. But. QScene3D - this is QML type. In my case need to use just QEntity as root entity. QExtrudedTextMesh - this is 3D text, mesh (but possible to use depth = 0). I would like to use 2dtext for ease main scene. – avttrue Oct 18 '19 at 06:17
  • I posted bugreport: [https://bugreports.qt.io/browse/QTBUG-79314](https://bugreports.qt.io/browse/QTBUG-79314) – avttrue Oct 18 '19 at 09:50
  • 1
    QML or not, you can always instantiate the object with C++. But I would try simpler QML for prototyping first. Have a look at this guy project: https://github.com/MASKOR/Qt3DPointcloudRenderer – Alexander V Oct 18 '19 at 15:00
  • In 5.14, the main problem is fixed. Another problem and solution is described [here](https://forum.qt.io/topic/92944/qt3d-how-to-print-text-qtext2dentity/7). – avttrue Jan 09 '20 at 13:48
  • Good to know they fixed it. – Alexander V Jan 09 '20 at 16:49

1 Answers1

2

There is an example on Stackoverflow in QML, where you can see that Text2Dentity is used in another Entity.

Entity {
        id: textFront
        components: [ Transform { translation: Qt.vector3d(-12.5,-5,-20) } ] 

        Text2DEntity {
            font.family: "Sans Serif"
            font.pointSize: 3
            color: "white"
            text: "textFront"
            width: text.length * font.pointSize*2
            height: font.pointSize * 4
        }
    }
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Avery
  • 37
  • 1
  • 8
  • Avery, the same thing happens in this qml code as in my c++ code. My task is to try realise all in c++. I'll wait for an answer to my [bug report](https://bugreports.qt.io/browse/QTBUG-79314). – avttrue Oct 21 '19 at 07:12