如果要运行此应用程序,则显示消息“[Qt3DRender::GLTexture]尚未从Texture Generator生成QTextureData。该帧的纹理将无效”,并在退出时-应用程序崩溃。
创建QText2DEntity的错误是什么?如果要注释标记的片段,则不会有任何问题。
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
代码在Qt 5.13.1上进行了测试
最佳答案
Stackoverflow in QML上有一个示例,您可以看到Text2Dentity
在另一个实体中使用。
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
}
}
关于c++ - Qt3D:关于QText2DEntity的几个简单问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58434005/