标题:qt下opengl不调用paintgl是什么原因?
作者:gaoshiqing
日期:2017-11-13 14:24
内容:
TargetChartView3D::TargetChartView3D(QWidget* parent)
: QGLWidget(parent)
{
QVector3D pos(0.0, 0.0, 12.0);
QVector3D target(0.0, 0.0, 0.0);
QVector3D up(0.0, 1.0, 0.0);
setCamera(pos, target, up);
}
//TargetChartView3D::~TargetChartView3D()
//{
//}
void TargetChartView3D::initializeGL()
{
glShadeModel(GL_SMOOTH);//设置阴影平滑模式
glClearColor(1.0, 1.0, 1.0, 1.0);//改变窗口的背景颜色
glClearDepth(1.0);//设置深度缓存
glEnable(GL_DEPTH_TEST);//允许深度测试
glDepthFunc(GL_LEQUAL);//设置深度测试类型
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
slide(-0.50, 1.40, 0.50);
}
void TargetChartView3D::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
setModelViewMatrix();
GLDrawCubeCoordinates();
GLDrawSpaceAxes();
updateGL();
}
void TargetChartView3D::paintEvent(QPaintEvent *event)
{
update();
}
void TargetChartView3D::resizeGL(int width, int height)
{
if (height == 0)
{
height = 1;
}
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLfloat)width / (GLfloat)height, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
updateGL();
}
打开时能调用initializeGL和resizeGL,但不调用paintgl,而且之后也不再调用resizeGL, ..
#1 [大漠之鹰 11-14 14:23]
貌似流程不对吧,updateGL后会由QT自己调用paintGL。想要连续绘制的话,可以使用定时器绑定updateGL