Results 1 to 6 of 6

Thread: OpenGL in thread

  1. #1
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default OpenGL in thread

    Hello.
    I have a problem with a simple application. I have a window with a few widgets in it including a QGLWidget. I want to make an animation in the glwidget but everytime I start it, I cannot access the other widgets.
    I also tried with threads: I made a thread which increments a value and emits a signal when done. signal is connected to a glwidget class slot which draws the opengl object into the new position. Still, the application focuses on the opengl widget and cannot access other fuctions (widgets and menu items).
    Any ideea how can I solve this? I want opengl widget to redraw separately from the other widgets.... currently redrawing with updateGL().

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL in thread

    do you have a while loop or an expensive operation in your paintGL()?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: OpenGL in thread

    did you use timers ?
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  4. #4
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenGL in thread

    Quote Originally Posted by high_flyer View Post
    do you have a while loop or an expensive operation in your paintGL()?
    This is my paintGL:

    Qt Code:
    1. void GLWidget::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4. glLoadIdentity();
    5. glTranslated(0.0, 0.0, -10.0);
    6. glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
    7. glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
    8. glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
    9. glCallList(object);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 
    It's the hellogl's paintGL from examples, modified to rotate on Y with a certain angle, increment 1.

  5. #5
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenGL in thread

    Quote Originally Posted by john_god View Post
    did you use timers ?
    I tried with timers and now it works. This is what I have in the thread now:
    Qt Code:
    1. void GLThread::start_simulation()
    2. {
    3. connect(simtimer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
    4. simtimer->start(1);
    5. }
    To copy to clipboard, switch view to plain text mode 

    where:
    Qt Code:
    1. void GLThread::rotateOneStep()
    2. {
    3. i=i+Tspeed;
    4. emit changeVal(i);
    5. }
    To copy to clipboard, switch view to plain text mode 
    changeVal signal is connected with the openGL function which executes the rotation and has the updateGL() at the end.

    Is this the only way to do this? or is it the best way?

  6. #6
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: OpenGL in thread

    I'm not sure but I think you should put glClear(...) in the initializeGL() function.
    No need to keep calling it in paintGL() as you update drawings.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

Similar Threads

  1. Thread Ownership Problem
    By tntcoda in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 00:18
  2. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  3. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 13:36
  4. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  5. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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.