PDA

View Full Version : OpenGL Framebuffer



^NyAw^
18th March 2008, 12:16
Hi,

I just copied this code from "framebufferobject" example.



if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects ()) {
QMessageBox::information(0, "OpenGL framebuffer objects",
"This system does not support OpenGL/framebuffer objects.");
return -1;
}


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

My openGL widget constructor is



QOpenGLWidget::QOpenGLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers),parent)


I tryied to change it to



QOpenGLWidget::QOpenGLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::DirectRendering),parent)


The problem is that the images are not properly shown as you can see on the attached file.

Stukfruit
19th March 2008, 14:38
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 (http://www.realtech-vr.com/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.

^NyAw^
19th March 2008, 16:07
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,

Stukfruit
20th March 2008, 12:33
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.

^NyAw^
20th March 2008, 22:51
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:




void QOpenGLWidget::showImage(char* pcData,int iWidth,int iHeight)
{
makeCurrent();

glClear(GL_COLOR_BUFFER_BIT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
glTexImage2D(GL_TEXTURE_2D,0,1,iWidth,iHeight,0,GL _LUMINANCE,GL_UNSIGNED_BYTE,pcData);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(0.0f, 0.0f);

glTexCoord2f(1.0f, 1.0f);
glVertex2f(float(width()), 0.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex2f(float(width()), float(height()));

glTexCoord2f(0.0f, 0.0f);
glVertex2f(0.0f, float(height()));
glEnd();
glFlush();

updateGL();
}

Stukfruit
21st March 2008, 06:47
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).

^NyAw^
25th March 2008, 09:49
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,

Stukfruit
25th March 2008, 11:18
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?

:)

^NyAw^
25th March 2008, 11:45
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,

Stukfruit
25th March 2008, 12:28
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.

^NyAw^
25th March 2008, 12:42
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,