Results 1 to 2 of 2

Thread: Display image with qt & opengl, timing accuracy and vsync issues, c++

  1. #1
    Join Date
    Feb 2017
    Qt products

    Default Display image with qt & opengl, timing accuracy and vsync issues, c++

    I'm building a module that is supposed to display images at a certain rate (not pre defined, but not very high - 10Hz max for the swapping of images).

    From my research I got to the conclusion that QGLWidget is the right tool for this task, after enabling vsync with openGL calls(SwapInterval family).

    Yet, I am not sure how to actually implement the swapping mechanisem - should I use a timer? If I set a timer for 333.3 ms(3 Hz), when the refresh rate is 60 Hz (16.67 per cycle, thus the timer is 20 cycles), and I be sure that timing will be fine? And if the rate should be 9Hz, I need to set the timer for 100+16.67 because this is the best I can get? And if a timer is ok, should I just call paintGL() when it sends me the timeout event?
    Also, do you have any reference to actually displaying an image on a qglwidget? Everything I've tried wan't successful, for example this code:
    Qt Code:
    1. void imageDisplay::showImage()
    2. {
    3. glEnable(GL_TEXTURE_2D);
    4. drawTexture(QRect(0,0,1,1),texture,GL_TEXTURE_2D);
    5. glDisable(GL_TEXTURE_2D);
    7. }
    9. void imageDisplay::loadImage(QImage &img)
    10. {
    11. width_img=img.width();
    12. height_img=img.height();
    14. glEnable(GL_TEXTURE_2D); // Enable texturing
    15. glBindTexture(GL_TEXTURE_2D, texture); // Set as the current texture
    16. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
    19. glDisable(GL_TEXTURE_2D);
    20. updateGL();
    21. return;
    22. }
    To copy to clipboard, switch view to plain text mode 

    only draws a small part of my img on the bottom of the widget


  2. #2
    Join Date
    Mar 2008
    Kraków, Poland
    Thanked 284 Times in 279 Posts
    Qt products
    Unix/X11 Windows

    Default Re: Display image with qt & opengl, timing accuracy and vsync issues, c++

    Maybe use QTimer with 100 ms interval - it is 10 Hz.

Similar Threads

  1. Replies: 1
    Last Post: 18th October 2015, 13:06
  2. Replies: 1
    Last Post: 11th May 2015, 14:14
  3. QGraphicsView + opengl + Vsync
    By medved6 in forum Qt Programming
    Replies: 3
    Last Post: 11th March 2011, 17:20
  4. OpenGL issues with Qt 4.6 master
    By profoX in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2009, 16:31

Tags for this Thread


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.