Hi,

Here is my problem, I'm trying to update the QGLWidget from an other thread. But when i try i got this warning:
"QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"

I want to retrieve a video stream from a camera and display it on a QGLWidget. With the NVAPI, i fill one image in a GLTexture each frame. That's what i want to display. (and i have displayed it without update it in a thread)
But as i need to update it continously for the stream, i want to do it in a stream.

Here is my code:

Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3.  
  4. Widget::Widget(QGLWidget *parent) :
  5. QGLWidget(parent),
  6. ui(new Ui::Widget)
  7. {
  8. ui->setupUi(this);
  9. }
  10.  
  11. Widget::~Widget()
  12. {
  13.  
  14. nv.cleanupVideo();
  15. th.join();
  16. delete ui;
  17. }
  18.  
  19. void Widget::initializeGL(){
  20. glewInit();
  21. //Initialize the capture of the camera
  22. nv = NVConfig();
  23. this->contextGL = wglGetCurrentContext();
  24. nv.GlobalInit();
  25. nv.LockDevice(GetDC((HWND)this->winId()),this->contextGL);
  26. //Unbind the OpenGL context from this thread.
  27. wglMakeCurrent(0, 0);
  28. //Launch the capture on an other thread
  29. th = std::thread(&Widget::updateGL,this);
  30. }
  31.  
  32. void Widget::resizeGL(int w, int h){
  33. if(h==0)
  34. h =1;
  35. glViewport(0,0,w,h);
  36. glMatrixMode(GL_PROJECTION);
  37. glLoadIdentity();
  38. perspectiveGL(45.0f,w/h,0.1f,100.0f);
  39. glMatrixMode(GL_MODELVIEW);
  40. glLoadIdentity();
  41.  
  42. }
  43.  
  44. /*
  45. * The capture will fill a GL Texture 1280*720; GL_RGBA
  46. *
  47. */
  48. void Widget::updateGL(){
  49. //Start the capture, the previous OpenGL is bind again with
  50. // wglMakeCurrent(GetDC((HWND)this->winId()),this->contextGL)
  51. nv.StartCapture(GetDC((HWND)this->winId()),this->contextGL);
  52. }
  53.  
  54. void Widget::paintGL(){
  55. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  56. glLoadIdentity();
  57. glTranslatef(-1.5f,0.0f,-6.0f);
  58. glBegin(GL_QUADS);
  59. glTexCoord2f(0,1.0f);
  60. glVertex3f(0,0,0);
  61. glTexCoord2f(0,0);
  62. glVertex3f(0,1.0f,0);
  63. glTexCoord2f(1.0f,0);
  64. glVertex3f(1.0f,1.0f,0);
  65. glTexCoord2f(1.0f,1.0f);
  66. glVertex3f(1.0f,0,0);
  67. glEnd();
  68.  
  69.  
  70. }
  71.  
  72. void Widget::perspectiveGL(GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar){
  73. const GLdouble pi = 3.1415926535897932384626433832795;
  74. GLdouble fW, fH;
  75. fH = tan( fovY / 360 * pi) * zNear;
  76. fW = fH * aspect;
  77. glFrustum( -fW,fW,-fH,fH,zNear,zFar);
  78. }
To copy to clipboard, switch view to plain text mode