How to paint a text in OpenGL context mixing Qt

OpenGL is not convenient to draw text, then I want to paint a text in opengl context mixing using qt painter. From the qt document, if we want to using painter in opengl context, it will default disable depth test,

so the text in the back of the model will be painted in the front, like that:

WeChat Image_20200218160929
I want to draw model like this::

WeChat Image_20200218162158 WeChat Image_20200218162324

My code like that:

WeChat Image_20200218160910

please help me how to enable depth test to avoid drawing the text behind of the object to the front.

use QGLWidget::renderText(double x, double y, double z, QString str)

Thank you very much for your reply. My GLWidget is inherited from QOpenGLWidget, but not QGLWidget.

the QGLWidget is obsolete.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.