Results 1 to 2 of 2

Thread: QOpenGLContext::SwapBuffer error when using different widgets

  1. #1
    Join Date
    May 2017
    Posts
    8
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QOpenGLContext::SwapBuffer error when using different widgets

    Hi,

    I have a strange problem with my qt application. I have a custom QGLWidget which get a stream video from a camera. Like this:
    sans.jpg

    Ans as soon i put an other widget in an other layout, my custom widget stop rendering. Like this:
    avec.png

    And i got the error :
    Qt Code:
    1. QOpenGLContext::swapBuffers() called with non-exposed window, behaviour is undefined.
    To copy to clipboard, switch view to plain text mode 

    Here is the code of my custom widget:
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3.  
    4. Widget::Widget(QWidget *parent) :
    5. QGLWidget(parent),
    6. ui(new Ui::Widget)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. Widget::~Widget()
    12. {
    13. wglMakeCurrent(GetDC((HWND)this->winId()), this->contextGL);
    14. cu.ClearProcess(nvGl.m_videoBuffer);
    15. nvGl.cleanupVideo(GetDC((HWND)this->winId()));
    16. delete ui;
    17. }
    18.  
    19. void Widget::initializeGL(){
    20. glewInit();
    21. rec = Recorder();
    22. this->contextGL =wglGetCurrentContext();
    23. nvC = NVConfig();
    24. nvC.GlobalInit();
    25. nvGl = NVGL(nvC.l_vioConfig,GetDC((HWND)this->winId()));
    26. cu= CUGL();
    27. cu.InitProcess(nvGl.m_videoBuffer);
    28. QTimer::singleShot(16,this,SLOT(Tick()));
    29. }
    30.  
    31. void Widget::resizeGL(int w, int h){
    32. this->resize(w,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. void Widget::Tick(){
    44. nvC.DetectIStatus();
    45. nvC.setCaptureDevice();
    46. nvGl.StartCapture();
    47. cu.ProcessVideo(nvGl.m_videoBuffer);
    48. rec.RecordShot(nvGl.m_videoTexture);
    49. paintGL();
    50.  
    51. QTimer::singleShot(16,this,SLOT(Tick()));
    52. }
    53.  
    54. void Widget::paintGL(){
    55. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    56.  
    57. glLoadIdentity();
    58. glTranslatef(-0.5f,-.5f,-1.1f);
    59. glBegin(GL_QUADS);
    60. glTexCoord2f(0,0);
    61. glVertex3f(0,0,0);
    62. glTexCoord2f(0,1.0f);
    63. glVertex3f(0,1.0f,0);
    64. glTexCoord2f(1.0f,1.0f);
    65. glVertex3f(1.0f,1.0f,0);
    66. glTexCoord2f(1.0f,0);
    67. glVertex3f(1.0f,0,0);
    68. glEnd();
    69. }
    70. void Widget::Record(){
    71. rec.Start_StopRecord(nvGl.m_videoTexture);
    72. }
    73.  
    74.  
    75. void Widget::perspectiveGL(GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar){
    76. const GLdouble pi = 3.1415926535897932384626433832795;
    77. GLdouble fW, fH;
    78. fH = tan( fovY / 360 * pi) * zNear;
    79. fW = fH * aspect;
    80. glFrustum( -fW,fW,-fH,fH,zNear,zFar);
    81. }
    To copy to clipboard, switch view to plain text mode 

    If you have any idea.
    thanks in advance

  2. #2
    Join Date
    May 2017
    Posts
    8
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QOpenGLContext::SwapBuffer error when using different widgets

    Hi,

    So i've managed to draw something on my window (you can see it here :New.png )
    But I only get a white screen, during the creation of the QmainApllication, how does the different QGLWidget are handled? In the same thread? With only one GL Context?

    I can't find these informations on internet and it could be the reason of the white screen. Do you have any idea?

Similar Threads

  1. Not receving QOpenGLContext::aboutToBeDestroyed signal
    By FlawedLogic in forum Qt Programming
    Replies: 0
    Last Post: 3rd December 2015, 12:17
  2. Replies: 1
    Last Post: 7th April 2015, 08:05
  3. Replies: 5
    Last Post: 3rd December 2014, 16:03
  4. Replies: 2
    Last Post: 20th September 2013, 23:47
  5. Replies: 0
    Last Post: 30th April 2012, 16:17

Tags for this Thread

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.