QOpenGLFramebufferObject and renderText does not work



  • I need to bind a QOpenGLFramebufferObject and render the text into it. I get two strange errors.

    @int gh = 0;

    Widget::Widget(QGLWidget *parent) : QGLWidget(parent) {
    this->setMinimumSize(500,500);
    }
    void Widget::initializeGL() {
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glMatrixMode(GL_PROJECTION);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    void Widget::paintGL() {
    if(gh == 0) {
    QOpenGLFramebufferObject *FBO = new QOpenGLFramebufferObject(this->width(),this->height(), QOpenGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGBA16);

        FBO->bind();
    
        renderText(100,100,"TEXTчврамиылвошаирпмыгш(345)вамываваи[e5674r56y345]");
        renderText(100,120,"sdrpvg9w34ty8w0c4892rtnw3y84rгшнты09у8мнце8934ец89ка");
        renderText(100,140,"ыхюыувчаъюхфцу=хзфъхзцулаб45ше-0395гн394г50234=-04-и");
        renderText(100,160,"ячсмитьбю.эждлорпавыффффйцукеннггшшщщззхъ=-0987654321");
        renderText(100,180,"TEXTчврамиылвошаирпмыгш(345)вамываваи[e5674r56y345]");
    
        FBO->release();
        FBO->toImage().save("R:/fbo.png");
    }
    gh++;
    

    }

    void Widget::resizeGL(int width, int height) {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, width, height);
    glOrtho(0,width, height,0,-1,1);
    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    }@

    The first error, if the code contains if (gh == 0), then the first call renderText, in FBO rendered only "TEXTchvramiylvoshairpmygsh (345) vamyvavai [e5674r56y345]", the others renderText's simply are not drawn , (in some cases even the first renderText drawn incompletely). Related problem - if I add after the last renderText rendering geometry (polygons, lines, ...), they are not drawn too. All the other renderText's drawn in the screen.
    That is, I see the first renderText in FBO, and all other renderText on the screen, why?

    http://s020.radikal.ru/i717/1402/96/0efac49e8dbd.png

    The second error - if I remove if (gh == 0), then the first call paintGL, in FBO appears "TEXTchvramiylvoshairpmygsh (345) vamyvavai [e5674r56y345]", the screen displays the remaining 4 renderText's. The second call paintGL, everything on the screen remains unchanged, but the other lines of text appear in the FBO.

    An alternative implementation does not eliminate the problem.

    @void Widget::paintGL(){
    if(gh == 0) {
    GLuint textureId;
    glGenTextures(1, &textureId);
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, this->width(), this->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

        GLuint fboId;
        glGenFramebuffers(1, &fboId);
        glBindFramebuffer(GL_FRAMEBUFFER, fboId);
    
        glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,textureId,  0);
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    
        renderText(100,100,"TEXTчврамиылвошаирпмыгш(345)вамываваи[e5674r56y345]");
        renderText(100,120,"sdrpvg9w34ty8w0c4892rtnw3y84rгшнты09у8мнце8934ец89ка");
        renderText(100,140,"ыхюыувчаъюхфцу=хзфъхзцулаб45ше-0395гн394г50234=-04-и");
        renderText(100,160,"ячсмитьбю.эждлорпавыффффйцукеннггшшщщззхъ=-0987654321");
        renderText(100,180,"TEXTчврамиылвошаирпмыгш(345)вамываваи[e5674r56y345]");
    
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }
    gh++;
    

    }@

    -3rd problem (it's not in the code). If I make 2 timers with different intervals, and the first timer's signal calls paintGL, and the second timer's signal calls drawing to FBO, the moments when both timers calls simultaneously, renderText draws immediately in the FBO and on the screen, why?
    makeCurrent(); does not help.

    Windows 7 64x; Qt Creater 2.8.1 (Qt 5.1.1 MSVC 2010, 32 bit)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.