Results 1 to 7 of 7

Thread: [openGL with Qt] updating of screen when paintGL is updated

  1. #1
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default [openGL with Qt] updating of screen when paintGL is updated

    Hello all,

    I have a problem with the display in OpenGL. Currently I have a program that plot little by little some things in an openGL window.

    => i want to update screen each time that i go in the method "plotGL" but i don't know how i can do that

    => I noticed that openGL screen is updated if I increase the size of the openGL window but this update of the display is not automatically

    So, How can I update my screen each time that i go in the paintGL function?

    thank you in advance for your help

    ps: I tried repaint () and updateGL () but it does not work then call these methods paintGL, it makes me so all block

    this is my code:
    Qt Code:
    1. void myGLWidget::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4. glClearColor(1.0f,1.0f,1.0f,1.0f);
    5. glMatrixMode( GL_MODELVIEW );
    6. glLoadIdentity( );
    7. gluLookAt( 1.2, 1.7, 1.0, 0, 0, 0, 0, 0, 1);
    8. glBegin(GL_LINES);
    9. //plot
    10. glEnd();
    11. // updateSCREEN();
    12. }
    To copy to clipboard, switch view to plain text mode 

    i have tried to decomment the line "updateSCREEN();" and put this method
    Qt Code:
    1. void myGLWidget::updateSCREEN()
    2. {
    3. updateGL();
    4. //repaint(); //i have tried this too
    5. }
    To copy to clipboard, switch view to plain text mode 

    but it don't works, it creates a general blocage of alls my windows

    Can you help me please? thanks a lot
    Last edited by 21did21; 6th July 2011 at 01:26.

  2. #2
    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 with Qt] updating of screen when paintGL is updated

    Hi
    First, you can put glClearColor(1.0f,1.0f,1.0f,1.0f) in your initializeGL() method, no need to keep calling it in paintGL().

    Second, if you use updateGL() inside paintGL(), you are creating a infinite loop, since, updateGL() keeps calling paintGL(), thats why your windows block.
    You have to put updateGL() some where else possibly inside your plotGL method
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  3. The following user says thank you to john_god for this useful post:

    21did21 (6th July 2011)

  4. #3
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: [openGL with Qt] updating of screen when paintGL is updated

    thank for your help i think my problem it's soon resolve
    regards

    EDIT:

    i have already a problem: my GL object was defined in the constructor of an other class, so now i can acces to this object to do:

    Qt Code:
    1. myWidgetGL->updateScreen()
    To copy to clipboard, switch view to plain text mode 

    so i want to make a method in the GLWidget class that is tell without this syntaxe....

    do you know how i can do that ?
    Last edited by 21did21; 6th July 2011 at 15:21.

  5. #4
    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 with Qt] updating of screen when paintGL is updated

    I don't need the updateScreen() method
    you can call directly myWidgetGL->updateGL();

    You have to find a logic in your program, that when a user does some input that change the drawing, you call the updateGL().
    For example some method like keypress event, where the user updates the scale, or the translation of the drawing. Than, in that method, you call updateGL() to fire the update in the drawing.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  6. #5
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: [openGL with Qt] updating of screen when paintGL is updated

    yes i use keypresse event so i update my openGL at this moment and it works.

    but i have a problem:
    => i have defined my GL widget in the constructor of one window, so i can't access to this widget in a other place

    for example:
    => in my main.cpp i can't do this:
    Qt Code:
    1. myGlWidget->updateGL();
    To copy to clipboard, switch view to plain text mode 
    because this widget is defined in the constructor of my main windows...

    so it's my problem to update the screen now...

  7. #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 with Qt] updating of screen when paintGL is updated

    In the constructor where you defined your glwidget add the following:

    Qt Code:
    1. setFocusPolicy(Qt::StrongFocus);
    To copy to clipboard, switch view to plain text mode 

    than implement a method for the keypressevent and in that method add


    Qt Code:
    1. void somewidget::keyPressEvent(QKeyEvent *event)
    2. {
    3. myGlWidget->->keyPressEvent(event);
    4. }
    To copy to clipboard, switch view to plain text mode 

    That way you'll be passing the event to the glwidget.

    ALso do you realize you can use qglwidget as a standalone window without making a child of another widget ? That way you wouldnt have this problem.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  8. The following user says thank you to john_god for this useful post:

    21did21 (6th July 2011)

  9. #7
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: [openGL with Qt] updating of screen when paintGL is updated

    thank for your help

    Quote Originally Posted by john_god View Post
    ALso do you realize you can use qglwidget as a standalone window without making a child of another widget ? That way you wouldnt have this problem.
    yes i think have to do this.

    thanks for all

    regards :-)

Similar Threads

  1. Qt + opengl+opencv black screen
    By loose in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2011, 15:49
  2. Capture OpenGL screen pixels
    By Windsoarer in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2009, 04:24
  3. QGraphicsView, OpenGL and repainting/updating
    By Amargedon in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2009, 12:03
  4. Help on OpenGL in PaintGL
    By mickey in forum Newbie
    Replies: 1
    Last Post: 15th April 2006, 22:17
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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
  •  
Qt is a trademark of The Qt Company.