Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 6.6.1 Android Build Error: use of undeclared identifier 'GL_DRAW_FRAMEBUFFER'
QtWS25 Last Chance

Qt 6.6.1 Android Build Error: use of undeclared identifier 'GL_DRAW_FRAMEBUFFER'

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 1 Posters 665 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 28 Dec 2023, 11:34 last edited by 8Observer8
    #1

    Hi,

    It is a continue of this topic: Why QSurfaceFormat is a cause of OpenGL error with the 1282 code (invalid operation) after glReadPixels call?

    It works on Desktop:

    6cd4543a-2bf2-4fbd-ae88-bd6ca36ac18d-image.png

    But when I switch to Android I have these errors:

    main.cpp:45:27: error: use of undeclared identifier 'GL_DRAW_FRAMEBUFFER'
    main.cpp:50:27: error: use of undeclared identifier 'GL_DRAW_FRAMEBUFFER'
    main.cpp:52:27: error: use of undeclared identifier 'GL_READ_FRAMEBUFFER'
    main.cpp:57:22: error: use of undeclared identifier 'GL_READ_FRAMEBUFFER'
    

    I connected the Redmi 4X phone (that supports OpenGL ES 3.2) using USB cable. This is a screenshot that I made on laptop using the scrcpy program:

    9324eb09-ca99-43c2-a9a3-3f590e709dd5-image.png

    main.cpp

    #include <QtGui/QOpenGLExtraFunctions>
    #include <QtGui/QSurfaceFormat>
    #include <QtGui/QVector3D>
    #include <QtOpenGL/QOpenGLFramebufferObject>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QLabel>
    #include <QtWidgets/QWidget>
    #include <QtWidgets/QVBoxLayout>
    #include <QtOpenGLWidgets/QOpenGLWidget>
    
    class OpenGLWidget : public QOpenGLWidget, private QOpenGLExtraFunctions
    {
        Q_OBJECT
    
    public:
        OpenGLWidget()
        {
            QSurfaceFormat surfaceFormat;
            surfaceFormat.setSamples(4);
            setFormat(surfaceFormat);
        }
    
    signals:
        void showInfoSignal(const QString &openGLVersion, const QString &shadingVersion,
                            const QString &vendor);
        void showPixelColorSignal(const QVector3D &color);
    
    private:
        void initializeGL() override
        {
            initializeOpenGLFunctions();
            glClearColor(0.f, 1.f, 0.f, 1.f);
            m_fbo.reset(new QOpenGLFramebufferObject(1, 1));
            QString version(QString("OpenGL version: %1").arg((const char*) glGetString(GL_VERSION)));
            QString shadingLanguageVersion(QString("GLSL version: %1")
                                               .arg((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)));
            QString vendor(QString("Vendor: %1").arg((const char*) glGetString(GL_VENDOR)));
            emit showInfoSignal(version, shadingLanguageVersion, vendor);
        }
    
        void paintGL() override
        {
            glClear(GL_COLOR_BUFFER_BIT);
            // Set draw buffer to be fbo. Read buffer is already the default one
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo->handle());
            // Blit from the default MSAA buffer to non-MSAA fbo
            glBlitFramebuffer(0, 0, m_fbo->width(), m_fbo->height(),
                              0, 0, m_fbo->width(), m_fbo->height(),
                              GL_COLOR_BUFFER_BIT, GL_NEAREST);
            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, context()->defaultFramebufferObject());
            // Set read buffer
            glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo->handle());
            // Read the pixel
            GLubyte pixel[4];
            glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
            // Set read buffer back to default
            glBindBuffer(GL_READ_FRAMEBUFFER, context()->defaultFramebufferObject());
            emit showPixelColorSignal(QVector3D(pixel[0] / 255.f, pixel[1] / 255.f, pixel[2] / 255.f));
        }
    
    private:
        std::unique_ptr<QOpenGLFramebufferObject> m_fbo;
    };
    
    class MainWindow : public QWidget
    {
        Q_OBJECT
    
    public:
        MainWindow()
        {
            resize(300, 300);
            setWindowTitle("Read Pixel Color");
    
            m_openGLVersionLabel = new QLabel();
            m_shadingLanguageVersionLabel = new QLabel();
            m_vendorLabel = new QLabel();
            m_pixelColorLabel = new QLabel();
            OpenGLWidget *openGLWidget = new OpenGLWidget();
    
            m_openGLVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
            m_shadingLanguageVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed,
                                                         QSizePolicy::Policy::Fixed);
            m_vendorLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
            m_pixelColorLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
    
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(m_openGLVersionLabel);
            layout->addWidget(m_shadingLanguageVersionLabel);
            layout->addWidget(m_vendorLabel);
            layout->addWidget(m_pixelColorLabel);
            layout->addWidget(openGLWidget);
            setLayout(layout);
    
            connect(openGLWidget, &OpenGLWidget::showPixelColorSignal,
                    this, &MainWindow::showPixelColorSlot);
            connect(openGLWidget, &OpenGLWidget::showInfoSignal, this, &MainWindow::showInfoSlot);
        }
    
    private slots:
        void showInfoSlot(const QString &openGLVersion, const QString &shadingVersion,
                          const QString &vendor)
        {
            m_openGLVersionLabel->setText(openGLVersion);
            m_shadingLanguageVersionLabel->setText(shadingVersion);
            m_vendorLabel->setText(vendor);
        }
    
        void showPixelColorSlot(const QVector3D &color)
        {
            m_pixelColorLabel->setText(QString("Pixel Color: (r: %1, g: %2, b: %3)")
                                           .arg(color.x()).arg(color.y()).arg(color.x()));
        }
    
    private:
        QLabel *m_openGLVersionLabel;
        QLabel *m_shadingLanguageVersionLabel;
        QLabel *m_vendorLabel;
        QLabel *m_pixelColorLabel;
    };
    
    #include "main.moc"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        MainWindow w;
        w.show();
        return app.exec();
    }
    

    pro

    QT += core gui openglwidgets widgets
    
    win32: LIBS += -lopengl32
    
    CONFIG += c++17
    
    SOURCES += \
        main.cpp
    
    TARGET = app
    
    1 Reply Last reply
    0
    • 8 8Observer8 referenced this topic on 28 Dec 2023, 11:36
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 28 Dec 2023, 11:50 last edited by
      #2

      I tried to rename GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER to GL_DRAW_FRAMEBUFFER_EXT and GL_READ_FRAMEBUFFER_EXT but it didn't help:

      fbd77463-8f33-47ca-b6c6-c25e1eb2f3ba-image.png

      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 29 Dec 2023, 19:06 last edited by 8Observer8
        #3

        Cross-refs:

        • https://stackoverflow.com/questions/77733588/qt-6-6-1-android-build-error-use-of-undeclared-identifier-gl-draw-framebuffer
        • https://community.khronos.org/t/qt-6-6-1-android-build-error-use-of-undeclared-identifier-gl-draw-framebuffer/110397
        1 Reply Last reply
        0
        • 8 Offline
          8 Offline
          8Observer8
          wrote on 30 Dec 2023, 03:58 last edited by 8Observer8
          #4

          I commented all lines of code except glClear() in the paintGL() method to show OpenGL version, GLSL version, and vendor. I ran the example on physical device connected with USB cable. OpenGL ES 3.2 supports GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER. But it looks like it doesn't.

          59d7e15b-0dfb-45a0-a175-726580f2ed8b-image.png

          1 Reply Last reply
          0
          • 8 Offline
            8 Offline
            8Observer8
            wrote on 30 Dec 2023, 11:54 last edited by 8Observer8
            #5

            I found a temporary solution that is good for me for now. I just deleted the sampling:

                OpenGLWidget()
                {
                    // QSurfaceFormat surfaceFormat;
                    // surfaceFormat.setMajorVersion(3);
                    // surfaceFormat.setMinorVersion(0);
                    // surfaceFormat.setSamples(4);
                    // setFormat(surfaceFormat);
                }
            

            In this case I don't need to use GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER to read a pixel color using glReadPixels():

                void paintGL() override
                {
                    glClear(GL_COLOR_BUFFER_BIT);
                    // // Set draw buffer to be fbo. Read buffer is already the default one
                    // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo->handle());
                    // // Blit from the default MSAA buffer to non-MSAA fbo
                    // glBlitFramebuffer(0, 0, m_fbo->width(), m_fbo->height(),
                    //                   0, 0, m_fbo->width(), m_fbo->height(),
                    //                   GL_COLOR_BUFFER_BIT, GL_NEAREST);
                    // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, context()->defaultFramebufferObject());
                    // // Set read buffer
                    // glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo->handle());
            
                    // Read the pixel
                    GLubyte pixel[4];
                    glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
                    // Set read buffer back to default
                    // glBindBuffer(GL_READ_FRAMEBUFFER, context()->defaultFramebufferObject());
                    qDebug() << pixel[0] / 255.f << pixel[1] / 255.f << pixel[2] / 255.f;
                    emit showPixelColorSignal(QVector3D(pixel[0] / 255.f, pixel[1] / 255.f, pixel[2] / 255.f));
                }
            

            My applications works correctly on Android and WebAssembly. It read a pixel with green color (0, 1, 0):

            Android:

            3e5c60e0-dc68-457d-a30b-14b46bc6204d-image.png

            WebAssembly:

            cff10b89-1303-476b-bd69-e343bc13872a-image.png

            1 Reply Last reply
            0

            1/5

            28 Dec 2023, 11:34

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved