Results 1 to 11 of 11

Thread: OpenGL Framebuffer

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default OpenGL Framebuffer

    Hi,

    I just copied this code from "framebufferobject" example.

    Qt Code:
    1. if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
    2. QMessageBox::information(0, "OpenGL framebuffer objects",
    3. "This system does not support OpenGL/framebuffer objects.");
    4. return -1;
    5. }
    To copy to clipboard, switch view to plain text mode 

    On a notebook it is returning me false on "hasOpenGLFramebufferObjects".

    My openGL widget constructor is

    Qt Code:
    1. QOpenGLWidget::QOpenGLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers),parent)
    To copy to clipboard, switch view to plain text mode 

    I tryied to change it to

    Qt Code:
    1. QOpenGLWidget::QOpenGLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::DirectRendering),parent)
    To copy to clipboard, switch view to plain text mode 

    The problem is that the images are not properly shown as you can see on the attached file.
    Attached Images Attached Images
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    If the graphics card / graphics driver in/on your notebook doesn't support FBO's (Framebuffer Objects), there's no way to make them work except by upgrading your notebook or updating the driver for your video card (if you're using an old driver it may add support for the FBO extension).

    If you do have a relatively modern video card in your notebook and think the extension should be supported on it, you could try checking out what extensions you have using glView (free download). If it's not there and your video card is not an old one, again, try updating your drivers.

    If you notebook does have support for FBO, make sure that your OpenGL context is activated (ie. makeCurrent) before calling any FBO stuff (but afaik it shouldn't really matter when you use the QGL-classes/methods).

    Without support for the FBO extensions it does not matter if you change the app to render directly to the front buffer (which is useless in these days where compositing managers are used on nearly every OS). It will just not work without the extension. What you're seeing now is just random garbage.

    You might check out pixelbuffers, but I'm afraid those aren't really going to be supported on your card either, if even FBO's aren't. It's not a wise idea to use those anyway because FBO's seem to be the future.
    Last edited by Stukfruit; 19th March 2008 at 14:42.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Hi,

    My notebook is "Toshiba Tecra A8" with "Mobile Intel 945GM Express Chipset" as graphic chipset.

    I have tryied OpenGL extensions viewer and as you said, "No Frame buffer object support".

    I'm really new to OpenGL and I'm using "glTexImage2D" to show images. On my workstation is working well but now that I'm using a notebook I'm having this problem. Do you know another way to do the same "glTexImage2D" without using it?

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    glTexImage2D can be used on all graphic cards/drivers, just not together with FBO's if they aren't supported.

    But perhaps you can explain what you're trying to achieve?

    If all you want to do is to display images, you don't have to render to a texture.

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Hi,

    Yes, I want to display an image that is coming as "char*" on 8bpp. I wan to to use OpenGL to increase speed and decrease CPU usage.

    I'm new to OpenGL and the first way that I was able to show images was using this pice of code:

    Qt Code:
    1. void QOpenGLWidget::showImage(char* pcData,int iWidth,int iHeight)
    2. {
    3. makeCurrent();
    4.  
    5. glClear(GL_COLOR_BUFFER_BIT);
    6.  
    7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    9. glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    10. glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
    11. glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
    12. glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
    13. glTexImage2D(GL_TEXTURE_2D,0,1,iWidth,iHeight,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pcData);
    14.  
    15. glBegin(GL_QUADS);
    16. glTexCoord2f(0.0f, 1.0f);
    17. glVertex2f(0.0f, 0.0f);
    18.  
    19. glTexCoord2f(1.0f, 1.0f);
    20. glVertex2f(float(width()), 0.0f);
    21.  
    22. glTexCoord2f(1.0f, 0.0f);
    23. glVertex2f(float(width()), float(height()));
    24.  
    25. glTexCoord2f(0.0f, 0.0f);
    26. glVertex2f(0.0f, float(height()));
    27. glEnd();
    28. glFlush();
    29.  
    30. updateGL();
    31. }
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

  6. #6
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Yes, that should work, you don't need FBO's for that.

    But to be honest, if that's all you want to do (ie. displaying an image with the size of your view), it's not worthy to spend your time on it and much better to use Qt (QPainter) instead.

    There's too much overhead for such a simple operation as displaying a single image. OpenGL won't speed that up, and (if you don't know how to use it correctly) will actually slow your app down when you're uploading lots of images or upload data to vram multiple times a second.

    Using QPainter gives you the advantage of having more options as well (alpha blending with widgets on the background, blending modes, etc).

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Hi,

    Sorry for delay,

    But to be honest, if that's all you want to do (ie. displaying an image with the size of your view), it's not worthy to spend your time on it and much better to use Qt (QPainter) instead.
    Yes, QPainter will be easy to use, but my application is time critical and don't want to spend time on displaying images. So I decided that OpenGL be useful
    for this purpose.

    Thanks,
    Òscar Llarch i Galán

  8. #8
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    If you're doing it like you've shown in this topic, you will (on each "showImage") do an expensive context switch, you will indirectly use CPU-time to upload (copy) the complete image data to vram, use even more CPU-time to do conversion between formats, use GPU-time to render the image to the backbuffer (if not using direct rendering, but that's ugly), and then copy the rendered image on the backbuffer back to your view using your CPU. Not to mention the forced flushes of the pipeline you're doing, stalling all operations for the GPU (not really important here, but if you're going to display a lot of things, it is).

    Do you think that's less expensive and faster than just copying the image data to a memory buffer (in system memory) and drawing only parts of it when necessary?


  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Hi,

    Conversion of image formats don't have to be done by CPU because the images are gray images(8 bit per pixel).
    Imagine that you have 4 cameras that you want to show all images and all of them are acquyring 70 fps with a resolution of 1024x1024. If I use software to display images I have an overhead that don't let me use other threads to do some work on those images.
    So, for this reason I need hardware acceleration to show images to have more CPU time.

    Thanks,
    Òscar Llarch i Galán

  10. #10
    Join Date
    Feb 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Sorry, missed the grayscale thing.
    Anyway, I'm not going to try to convince you just telling from my own experiences here.

    Just know that it's very slow to copy so much image data to vram so many times per second. There are OpenGL extensions to speed that up (pixelbuffer object springs to mind), but I'm afraid your card won't have support for that extension.

  11. #11
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Framebuffer

    Hi,

    Well, If threre is not any other way to do that, I will have to use software displaying when BFO extension is not avaiable.

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. Replies: 3
    Last Post: 12th February 2008, 21:17
  3. openGL with QT
    By me_here_me in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2007, 01:19
  4. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  5. OpenGL ES, Qt/11 - Qtopia Core?
    By zelko in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 10: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.