Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: display framebuffer on screen

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    21

    display framebuffer on screen

    a questions are :
    1) how to paint framebuffer on a screen ?
    2) why rendering the same picture directly on screen is about 10 times slower than renering to frambuffer ? (i have much slower g. card than the rest)
    3) im using texture from that framebuffer to display it on screen. but it is not working why ? the simple code belows. frambuffer
    context is good.

    Code :
    void oglPlotWidget::renderOffScreen() {
     
        makeCurrent();
     
        fb = new QGLFramebufferObject(this->width(), this->height(), GL_TEXTURE_2D);
        fb->bind();
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glViewport(0, 0, this->width(), this->height());
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho (-0.01, 2.01, -0.01, 2.01, 0, 1);
        glMatrixMode(GL_MODELVIEW);
     
        foreach(plotCurve *curve, m_curves)
        if (curve->style() == plotCurve::points)
        {
            QVector<SamplePointer> samples = curve->samples(); 
            glVertexPointer(2, GL_FLOAT, sizeof(SamplePointer), samples.data() + curve->firstSample());
            glColor3f(1, 0.1, 0.1);
            glPointSize(10);
            glDrawArrays(GL_POINTS, 0, samples.size() - curve->firstSample());
        }
     
        fb->release();
        textureId = fb->texture();
     
        delete fb;
     
    }

    and to paint just generated textureId i use :
    Code :
    void oglPlotWidget::paintGL() {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
     
        if(textureId)
        {
        glBindTexture(GL_TEXTURE_2D, textureId);
     
           glBegin(GL_QUADS);
     
           glTexCoord2f(0.0, 0.0);
           glVertex3f(-1.0, -1.0, 0.0);
     
           glTexCoord2f(0.0, 1.0);
           glVertex3f(-1.0, 1.0, 0.0);
     
           glTexCoord2f(1.0, 1.0);
           glVertex3f(1.0, 1.0, 0.0);
     
           glTexCoord2f(1.0, 0.0);
           glVertex3f(1.0, -1.0, 0.0);
     
           glEnd();
     
        }
    ...
    Last edited by rafal; 04-26-2012 at 05:12 AM.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    glOrtho (-0.01, 2.01, -0.01, 2.01, 0, 1);
    Are you sure your ortho projection values are right? Usually you set up a 2D screen using the width & height values that you use for the viewport.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glViewport(0, 0, this->width(), this->height());
    glMatrixMode(GL_PROJECTION);
    Not necessarily a problem...but your code is not clear if this is setting ModelView matrix to identity.

    glVertex3f(-1.0, -1.0, 0.0);

    glTexCoord2f(0.0, 1.0);
    glVertex3f(-1.0, 1.0, 0.0);

    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 1.0, 0.0);

    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, -1.0, 0.0);
    The vertex coordinates of a 2D screen are usually the width and height values of the glOrtho & viewport parameters.
    As you have not done that and rolled your own (which I don't understand) you need to check if these are the correct coordinates. Remeber, these coordinates will be transformed by the ModelView and Projection matricies, so the values you use here are very much linked to the projection matrix you setup earlier.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    21
    new coord values are :
    Code :
           glTexCoord2f    (0.0, 0.0);
           glVertex2f    (0.0, 0.0);
     
           glTexCoord2f    (0.0, 1.0);
           glVertex2f    (0.0, 2.0);
     
           glTexCoord2f    (1.0, 1.0);
           glVertex2f    (2.0, 2.0);
     
           glTexCoord2f    (1.0, 0.0);
           glVertex2f    (2.0, 0.0);

    but it isnt problem at all. im interesting in that why i see solid polygon instead of texture.

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    445
    Have you remembered to include
    Code :
     glEnable(GL_TEXTURE_2D);
    and if you have done this, do you have a mipmap complete texture? ie. all texture levels populated, or mipmaps disabled - see http://www.opengl.org/wiki/Common_Mi...ting_a_Texture

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    21
    sure i have glEnable(GL_TEXTURE_2D); and any line with mipmap which means disabled i think. i use texture to display framebuffer as i pointed before. is it the best way to do that ?
    Last edited by rafal; 04-26-2012 at 07:49 AM.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    You can also use glBlitFramebuffer to perform the copy. It's more convenient and you can skip that deprecated immediate mode full screen quad drawing code.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •