PDA

View Full Version : openGL with QT



me_here_me
1st July 2007, 13:51
Hi
I have an application built in QT and openGL. I have three widgets in the application and all of the widgets have a separate openGL context.

I want to keep a single openGL context for all of them now. Is there some simple and quick way through which I can change three contexts into one. (ask me for code snippets if I am not clear)

secondly, with the single OpenGL context, would I have a single InitializeGL, resizeGL and paintGL method?

any link to some quick tutorial

regards

me_here_me
1st July 2007, 15:14
consider that I have the following two widgets:



class CRayProfileWidget : public QGLWidget {

Q_OBJECT

public:
CRayProfileWidget(QWidget *parent = 0);

QSize minimumSizeHint() {
return QSize(256, 128);
}

QSize sizeHint() {
return QSize(256, 128);
}

protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();

private:
};


and the second one is exactly the same except the name :)



class CRayProfileWidget2 : public QGLWidget {

Q_OBJECT

public:
CRayProfileWidget2(QWidget *parent = 0);

QSize minimumSizeHint() {
return QSize(256, 128);
}

QSize sizeHint() {
return QSize(256, 128);
}

protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();

private:
};


and the main window containing both of these widgets is like:


///////////////////////////////////////
// main window

class Window : public QWidget {

Q_OBJECT

public:
Window(QWidget *parent = 0);

QSize sizeHint() const {
return QSize(800, 950);
}
};


both of the above widgets have a seperate rendering context. I want that they both share the same OpenGL rendering context.

how can I do that?

thanks in advance

minimoog
1st July 2007, 15:52
class CRayProfileWidget2 : public QGLWidget {

Q_OBJECT

public:

CRayProfileWidget2(QWidget *parent = 0, QGLWidget * shareWidget = 0);
.....
}


Look the documentation of the QGLWidget constructor.

me_here_me
1st July 2007, 16:17
thanks for the help

can you be a bit more elaborate please. I am new to QT and have very hard time making my way out of this problem of sharing openGL context.

what should be the parent in my case? should that be Window? but the window is QWidget and not QGLWidget.

If both widgets have the same parent, do I need to share display lists through shareWidget parameter?

Which of the widgets will have the initializeGL, resizeGL and paintGL methods? or should I
define them all in both the classes?

is there some code snippet as example out there?

regards

minimoog
2nd July 2007, 02:19
http://doc.trolltech.com/4.3/opengl-textures.html