QGLWidget在Windows 7中显示为黑色 [英] QGLWidget appears black in Windows 7

查看:304
本文介绍了QGLWidget在Windows 7中显示为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2010在Windows XP(Qt 4.7.2)中编写并测试了一些代码,然后在另一台安装了Windows 7的计算机上尝试过。

I wrote and tested some code in a Windows XP (Qt 4.7.2) using Visual Studio 2010 and then I tried on another machine with Windows 7 installed.

程序打开一个QDialog并创建一个QGLWidget,其中显示网络摄像头图像(有一些处理)。在Windows XP中,图像显示正确,在我测试程序在Windows 7机器的时刻,QGLWidget变黑,没有显示图像。然而奇怪的是,当我在窗口周围移动并且离开屏幕的边界时,当我再次停止移动时,图像被立即显示为黑色,这使得我认为图像被正确地接收/处理(有时),这可能是QTimer的问题。

The program opens a QDialog and creates a QGLWidget where I show webcam images (with some processing). While in Windows XP the images are shown correctly, at the moment that I test the program in a Windows 7 machine, the QGLWidget turns black and no image is shown. It is strange, though, that when I move around the window and it gets out of the borders of the screen, the image is shown for an instant and pitch black when I stop moving again, which makes me think that the images are correctly received/processed (some times), and that it might be a problem with a QTimer.

相关代码为:

初始化:

void GLVideo::initializeGL()
{   
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // Some OpenCV processing

    // Here I declare the timer, might it be the problem?
    m_timer = new QTimer(this);
    connect( m_timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()) );
    m_timer->start( 33 );

}

每个超时调用的插槽:

void GLVideo::timeOutSlot() 
{
    ReceiveInfo();
    LoadTextures();
}

void GLVideo::LoadTextures() 
{   
    // Get the image from the webcam
    ProcessCamera();

    glBindTexture(GL_TEXTURE_2D, texture);  
    glTexImage2D( GL_TEXTURE_2D, 0, 3, qImage->width(), 
        qImage->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, qImage->bits());
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    updateGL();
}

void GLVideo::resizeGL( int width, int height )
{
    height = height?height:1;
    glViewport( 0, 0, (GLint)width, (GLint)height );
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

最后,Widget的paint函数:

And finally, the paint function of the Widget:

void GLVideo::paintGL()
{   
    glPushAttrib(GL_ALL_ATTRIB_BITS) ;
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    glPopAttrib() ;

    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D, texture);

    glColor4f(1.0f,1.0f,1.0f, 1.0f);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.65f, 1.24f, -3.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.65f, 1.24f, -3.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.65f,-1.24f, -3.0f);
        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.65f,-1.24f, -3.0f);
    glEnd();    

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    // Some 2D drawing:
}

我在做什么错了?

推荐答案

如果你的程序在Windows XP中运行,而不是在Windows 7中运行,我建议您检查是否有更新版本的显示驱动程序。

If your program works in Windows XP but not in Windows 7, I recommend that you should check if there is a newer version of the display driver.

这篇关于QGLWidget在Windows 7中显示为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆