PDA

View Full Version : grabWidget



mickey
1st March 2006, 23:17
Hi,
I need to grab only my QGLWidget. but grabWidget take only QWidget?
This below grab only a gray square!

QPixmap qp = QPixmap::grabWidget(myGLWidget, 0,0, -1, -1);
Is there a way or I must use grabWindow?

jacek
1st March 2006, 23:23
Use QGLWidget::renderPixmap().

mickey
4th March 2006, 15:41
the problem of this function is that (I read) will start initalizeGL, paintGL() etc...and after this call my contextGL() changes! There are some problem. I don't know if are there ways to avoid this...

I tried use grabWindow.it grab all widget are on my interest widget :( But very problem of this is that it grab also a QMessageBox::warning that is launched a bit before of grabbing. How can I avoid this?

Thanks

jacek
4th March 2006, 16:00
the problem of this function is that (I read) will start initalizeGL, paintGL() etc...and after this call my contextGL() changes! There are some problem. I don't know if are there ways to avoid this...
Why do you want avoid this? If you implement these methods properly you shouldn't have any problems.


I tried use grabWindow.it grab all widget are on my interest widget :( But very problem of this is that it grab also a QMessageBox::warning that is launched a bit before of grabbing. How can I avoid this?
In Qt3 QGLWidget bypasses the Qt painting engine, so you must use QGLWidget::renderPixmap(). You can also try to make a screenshot.

mickey
4th March 2006, 16:02
Why do you want avoid this? If you implement these methods properly you shouldn't have any problems.

my texture are destroyed after renderPixmap! If I use grabWindow this not happen.....

jacek
4th March 2006, 16:41
my texture are destroyed after renderPixmap! If I use grabWindow this not happen.....
How do you initialize those textures?

mickey
4th March 2006, 21:49
yes, in initalializeGL()

jacek
4th March 2006, 22:10
yes, in initalializeGL()
But how do you initialize those textures?

mickey
5th March 2006, 01:54
//initializeGL()
per.myinitGL();
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glDisable(GL_TEXTURE_2D);

perc::myInitGL() {
glGenTextures(1, &tex);
QImage img;
if ( !img.load(texFileName)) {
QImage buf;
buf.fill(Qt::gray.rgb() );
img=buf;
}
QImage tx = QGLWidget::convertToGLFormat (img);
glBindTexture(GL_TEXTURE_2D, tex);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, tx.width(), tx.height(), GL_RGBA, GL_UNSIGNED_BYTE, tx.bits() );
}
Is it ok? It seems works properly....

jacek
5th March 2006, 02:09
Is it ok? It seems works properly....
Every time initializeGL() is called, per.myinitGL() will overwrite the tex variable. Maybe it will be enough, if you check whether initializeGL() is called for the first time and only then call per.myinitGL()?

What is that "per" object?

mickey
5th March 2006, 02:32
'per' is my object on I put texture...a square; Are you saying me that when I call renderpixmap(), initializeGL() starts and tex is overwrite? (But tex should be the same before......).
But what is the advantage for renderPixmap() of re-call initializeGL and PaintGL()? Isn't it a time lose?

jacek
5th March 2006, 16:44
QPixmap QGLWidget::renderPixmap ( int w = 0, int h = 0, bool useContext = FALSE ) [virtual]
Renders the current scene on a pixmap and returns the pixmap.
[...]
This method will create a pixmap and a temporary QGLContext to render on the pixmap. It will then call initializeGL(), resizeGL(), and paintGL() on this context. Finally, the widget's original GL context is restored.
[...]
If useContext is TRUE, this method will try to be more efficient by using the existing GL context to render the pixmap. The default is FALSE. Only use TRUE if you understand the risks.
Overlays are not rendered onto the pixmap.
If the GL rendering context and the desktop have different bit depths, the result will most likely look surprising.
Note that the creation of display lists, modifications of the view frustum etc. should be done from within initializeGL(). If this is not done, the temporary QGLContext will not be initialized properly, and the rendered pixmap may be incomplete/corrupted.
Your initializeGL() must be written in such way that it can be called multiple times and you must make sure that after renderPixmap() you restore the previous state. For example if you create textures in initializeGL() then after renderPixmap() you should use old texture ids.

You can also try to reuse the constext (see the docs), but pixmap may have a different colour depth than the screen.

mickey
17th March 2006, 12:18
Hi, the problem wasn't renderPixmap() ( that calls initializeGL() and paintGL().
renderPixmap() starts when I save my scene; it works properly if I simple save (without open saveDialogFile). If saveDialogFile starts and I click 'ok' button my contextGL broke;
It's strange.....