Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-14410

OpenGL text positioning on Linux is off-by-one

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 4.8.0
    • 4.7.0
    • GUI: Text handling
    • None
    • 354246566cf86f687ee897f95586ac17b5deb35c

      When text is painted with QPainter to an FBO on Linux (with Freetype font engine), then the characters are shifted one pixel to the left compared to when they are drawn using the raster engine.

      Run the following example to see. The top "Q" is painted with the raster engine and the bottom "Q" is painted into an FBO with the OpenGL engine. The bottom "Q" is one pixel to the left of the top "Q".

      #include <QtGui>
      #include <QtOpenGL>
      
      class MyGL : public QGLWidget
      {
      public:
          MyGL() : QGLWidget() {
              makeCurrent();
              QGLFramebufferObjectFormat fboFormat;
              fbo = new QGLFramebufferObject(800, 800, fboFormat);
          }
      
          void paintEvent(QPaintEvent *) {
              {
                  QPainter p(fbo);
                  p.fillRect(0, 0, 50, 20, Qt::white);
                  p.fillRect(10, 0, 10, 20, Qt::yellow);
      
                  p.drawText(10, 10, "Q");
              }
      
              QImage rasterEngineImage(50, 20, QImage::Format_ARGB32_Premultiplied);
              {
                  QPainter p(&rasterEngineImage);
                  p.fillRect(0, 0, 50, 20, Qt::white);
                  p.fillRect(10, 0, 10, 20, Qt::yellow);
      
                  p.drawText(10, 10, "Q");
                  p.end();
              }
      
              QImage openglEngineImage = fbo->toImage();
      
              {
                  QPainter p(this);
                  p.fillRect(rect(), Qt::white);
      
                  p.drawImage(0, 0, rasterEngineImage);
                  p.drawImage(0, rasterEngineImage.height(), openglEngineImage);
              }
      
          }
      
      private:
          QGLFramebufferObject *fbo;
      };
      
      
      int main(int argc, char **argv)
      {
          QApplication a(argc, argv);
          MyGL m;
          m.show();
          return a.exec();
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            esabraha Eskil Abrahamsen Blomfeldt
            esabraha Eskil Abrahamsen Blomfeldt
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes