Results 1 to 5 of 5

Thread: openGL with QT

  1. #1
    Join Date
    Jul 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question openGL with QT

    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

  2. #2
    Join Date
    Jul 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: openGL with QT

    consider that I have the following two widgets:

    Qt Code:
    1. class CRayProfileWidget : public QGLWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. CRayProfileWidget(QWidget *parent = 0);
    7.  
    8. QSize minimumSizeHint() {
    9. return QSize(256, 128);
    10. }
    11.  
    12. QSize sizeHint() {
    13. return QSize(256, 128);
    14. }
    15.  
    16. protected:
    17. void initializeGL();
    18. void resizeGL(int w, int h);
    19. void paintGL();
    20.  
    21. private:
    22. };
    To copy to clipboard, switch view to plain text mode 

    and the second one is exactly the same except the name

    Qt Code:
    1. class CRayProfileWidget2 : public QGLWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. CRayProfileWidget2(QWidget *parent = 0);
    7.  
    8. QSize minimumSizeHint() {
    9. return QSize(256, 128);
    10. }
    11.  
    12. QSize sizeHint() {
    13. return QSize(256, 128);
    14. }
    15.  
    16. protected:
    17. void initializeGL();
    18. void resizeGL(int w, int h);
    19. void paintGL();
    20.  
    21. private:
    22. };
    To copy to clipboard, switch view to plain text mode 

    and the main window containing both of these widgets is like:
    Qt Code:
    1. ///////////////////////////////////////
    2. // main window
    3.  
    4. class Window : public QWidget {
    5.  
    6. Q_OBJECT
    7.  
    8. public:
    9. Window(QWidget *parent = 0);
    10.  
    11. QSize sizeHint() const {
    12. return QSize(800, 950);
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by me_here_me; 1st July 2007 at 14:20. Reason: updated contents

  3. #3
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: openGL with QT

    Qt Code:
    1. class CRayProfileWidget2 : public QGLWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6.  
    7. CRayProfileWidget2(QWidget *parent = 0, QGLWidget * shareWidget = 0);
    8. .....
    9. }
    To copy to clipboard, switch view to plain text mode 

    Look the documentation of the QGLWidget constructor.
    Last edited by minimoog; 1st July 2007 at 14:59.

  4. #4
    Join Date
    Jul 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: openGL with QT

    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

  5. #5
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

Similar Threads

  1. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  2. Replies: 0
    Last Post: 4th May 2007, 10:44
  3. OpenGL ES, Qt/11 - Qtopia Core?
    By zelko in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 10:56
  4. 3 Dimensions using opengl
    By vermarajeev in forum Qt Programming
    Replies: 30
    Last Post: 23rd April 2007, 11:31
  5. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40

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.