Results 1 to 8 of 8

Thread: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

  1. #1
    Join Date
    Apr 2007
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    I wrote some code for test:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtOpenGL/QGLWidget>
    3. #include <QtOpenGL/QGLFramebufferObject>
    4.  
    5. class GLWidget : public QGLWidget {
    6. public:
    7. GLWidget() {
    8. m_big = font();
    9. m_big.setPixelSize(100);
    10. makeCurrent();
    11. m_fbo = new QGLFramebufferObject(500, 150);
    12. m_fbo->bind();
    13. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    14. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    15. QPainter painter(m_fbo);
    16. painter.setFont(m_big);
    17. painter.drawText(QRect(0, 0, 500, 150), "Test Text");
    18. m_fbo->release();
    19. }
    20. ~GLWidget() {
    21. delete m_fbo;
    22. }
    23. private:
    24. void paintEvent(QPaintEvent *) {
    25. QPainter painter(this);
    26. painter.setFont(m_big);
    27. painter.drawText(QRect(0, 0, 500, 150), "Test Text");
    28. drawTexture(QPointF(0.0, 150.0), m_fbo->texture());
    29. }
    30. QFont m_big;
    31. };
    32.  
    33. int main(int argc, char *argv[]) {
    34. QApplication app(argc, argv);
    35. GLWidget w;
    36. w.show();
    37. return app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

    The above codes do drawing two lines of "Test Text" on QGLWidget.
    Upper one is done by directly onto QGLWidget with QPainter, and the lower one is done by drawTexture whose texture is drawn in QGLFramebufferObject.

    The result is attached.
    result.png

    Both of them have problems.

    Upper one(drawn by QGLWidget with QPainter) is not anti-aliased.
    Lower one(drawn by QGLFramebufferObject) just shows black box.

    Also, when I tried with multi-sampled QGLWidget(with like QGLFormat::setSamples(4)), Upper one looks as same as lower one, that is, only black box.

    If you try with small font size, both of them display the texts normally.

    Is this a bug? or Did I mistake something?

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    Hi!

    1) Have you tried enabling High Quality OpenGL AntiAliasing on the painter?
    painter.setRenderHints(QPainter::Antialiasing|QPai nter::TextAntialiasing|QPainter::SmoothPixmapTrans form|QPainter::HighQualityAntialiasing);

    2) Is your big font exceeding the bounding rect you are passing to drawText?

    3) You set your glClearColor to black. How can you see black text at all? You should probably put your gl initialization code into initializeGL for it to work.

    HIH

    Joh

  3. #3
    Join Date
    Apr 2007
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    To JohannesMunk:

    1) Nothing changes.

    2) No. The bounding rect is large enough to display all texts.

    3) It's for QGLFramebufferObject(fbo) not QGLWidget.
    And, the clear color is not black, but transparent.
    If you set it to (1.0, 1.0, 1.0, 1.0), the background color of fbo just becomes white, and still exists the problem.

    Thank you for your reply.

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    1)
    Quote Originally Posted by xylosper View Post
    And, the clear color is not black, but transparent.
    You are right! Missed that.

    2) What happens if you take the same big font to a QGraphicsTextItem in a QGraphicsScene with an OpenGL Viewport?

    3) As workaround: Why don't you take the smaller font and scale the painter before drawing?

    Johannes

  5. #5
    Join Date
    Apr 2007
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    Thanks again, Johannes.

    I'll try later with QGraphicsScene.

    Yes, I've already handled this problem with scaling.

  6. #6
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5 Qt/Embedded

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    I got the same result with Qt 5.1.1 in using QGraphicsWebView to show web content.
    Any idea or hint that I can solve this?

    TKS~

    Vic

  7. #7
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5 Qt/Embedded

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    I found this issue was reported.
    (https://bugreports.qt.io/browse/QTBU...dget%20font%22)

    Samuel mentioned,
    GL text rendering falls back to path rendering when the font size grows too big. To get antialiasing the QGLWidget needs QGL::SampleBuffers in the QGLFormat, and the FBO needs the stencil buffer attachment for the path rendering to work.

    I did add QGLFormat with QGL::StencilBuffer, however the text still a block.
    QGLFormat glFormat(QGL::StencilBuffer | QGL::SampleBuffers);

    Did I misunderstood what he means?

  8. #8
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt5 Qt/Embedded

    Default Re: Problem on drawing text of big font size on QGLWidget and QGLFramebufferObject

    I finally solve this issue by define QT_MAX_CACHED_GLYPH_SIZE = 128 (means maximum font size 127)
    QT_MAX_CACHED_GLYPH_SIZE default set to 64.

Similar Threads

  1. QGLWidget and QGLFramebufferObject
    By ConfusedSushi in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2010, 20:47
  2. Problem in font and size in mac and Xp
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2010, 14:02
  3. Replies: 1
    Last Post: 3rd December 2009, 15:21
  4. problem on QGLWidget and QGLFramebufferObject
    By xylosper in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2008, 11:57
  5. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.