添加文本停止渲染自定义GL项目

添加文本停止渲染自定义GL项目

问题描述:

我正在渲染一个自定义的OpenGL项目,最重要的是我想添加一些小部件。添加文本停止渲染自定义GL项目

到目前为止,它工作正常。这就是它的样子。

enter image description here

不过,现在我想通过一个Text项添加到OpenGL的:

Rectangle{ 
    id: logoTextBox 
    x: logoButton.x + logoButton.width 
    y: logoButton.y 
    width: 200 
    height: logoButton.height 
    color: "#EEEEEE" 

    Text{ 
     id: logoVersionBlurb 
     y: 10 
     x: 10 
     font.pointSize: 8 
     text: "Ver 1.0" 
     color: "black" 
    } 

    Text{ 
     id: logoNameBlurb 
     y: 20 
     x: 10 
     font.pointSize: 14 
     font.bold: true 
     text: "Please work" 
    } 
} 

和它看起来像这样: enter image description here

我还是想了OpenGL来渲染,但我想Text出现在它上面。有任何想法吗?

我在QML创造我GLContext这样的:

MyGLWidget{ 
    id: glWidget 
} 

这里是从C++文件

void MyGLWidget::sync() 
{ 
    if (!m_renderer) { 
     m_renderer = new MyGLRenderer(); 
     connect(window(), SIGNAL(beforeRendering()), m_renderer, SLOT(paint()), Qt::DirectConnection); 
    } 
    m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio()); 
} 

好了相关的方法,我已经找到了解决办法。我将文本的renderType设置为NativeRendering,并导致Triangle正确呈现。

Text{ 
     id:sizeDialogXText 
     color: "white" 
     y: sizeDialogTitleText.y + 20 
     x: sizeDialogTitleText.x 
     text: "X" 
     font.pointSize: 12 
     renderType: Text.NativeRendering //This is the important line 
    } 
+1

这是一种解决方法,甚至不能接近解决方案。在你的插槽中,你是在你找到它的时候离开GL状态,还是你在篡改它?如果是这样,请调用QQuickWindow :: resetOpenGLState。 – peppe