PDA

View Full Version : QOpenGLContext::SwapBuffer error when using different widgets



miyoku157
6th June 2017, 15:24
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:
12490

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

And i got the error :
QOpenGLContext::swapBuffers() called with non-exposed window, behaviour is undefined.

Here is the code of my custom widget:

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
QGLWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}

Widget::~Widget()
{
wglMakeCurrent(GetDC((HWND)this->winId()), this->contextGL);
cu.ClearProcess(nvGl.m_videoBuffer);
nvGl.cleanupVideo(GetDC((HWND)this->winId()));
delete ui;
}

void Widget::initializeGL(){
glewInit();
rec = Recorder();
this->contextGL =wglGetCurrentContext();
nvC = NVConfig();
nvC.GlobalInit();
nvGl = NVGL(nvC.l_vioConfig,GetDC((HWND)this->winId()));
cu= CUGL();
cu.InitProcess(nvGl.m_videoBuffer);
QTimer::singleShot(16,this,SLOT(Tick()));
}

void Widget::resizeGL(int w, int h){
this->resize(w,h);
if(h==0)
h =1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
perspectiveGL(45.0f,w/h,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}
void Widget::Tick(){
nvC.DetectIStatus();
nvC.setCaptureDevice();
nvGl.StartCapture();
cu.ProcessVideo(nvGl.m_videoBuffer);
rec.RecordShot(nvGl.m_videoTexture);
paintGL();

QTimer::singleShot(16,this,SLOT(Tick()));
}

void Widget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glTranslatef(-0.5f,-.5f,-1.1f);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(0,0,0);
glTexCoord2f(0,1.0f);
glVertex3f(0,1.0f,0);
glTexCoord2f(1.0f,1.0f);
glVertex3f(1.0f,1.0f,0);
glTexCoord2f(1.0f,0);
glVertex3f(1.0f,0,0);
glEnd();
}
void Widget::Record(){
rec.Start_StopRecord(nvGl.m_videoTexture);
}


void Widget::perspectiveGL(GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar){
const GLdouble pi = 3.1415926535897932384626433832795;
GLdouble fW, fH;
fH = tan( fovY / 360 * pi) * zNear;
fW = fH * aspect;
glFrustum( -fW,fW,-fH,fH,zNear,zFar);
}


If you have any idea.
thanks in advance

miyoku157
8th June 2017, 12:01
Hi,

So i've managed to draw something on my window (you can see it here :12496 )
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?