Bad repaint QGLWidget ?
-
Hi everybody,
First I give you the code causing the problems.
Here is Display.cpp:
void KinectDisplay::initializeGL() { glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glDisable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); } void KinectDisplay::resizeGL(int w = GL_WIN_SIZE_X, int h = GL_WIN_SIZE_Y) { // Setup the OpenGL viewpoint // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); // Set the viewport to be the entier window glViewport(0.0, 0.0, w, h); // Set the correct perspective gluPerspective(45.0, 4.0/3.0, 0.0001, 10000); // Get back to the modelview glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set the camera gluLookAt(eyeX, eyeY, eyeZ, centerX + eyeX, centerY + eyeY, centerZ + eyeZ, 0.0, 1.0, 0.0); } void KinectDisplay::paintGL() { glBegin(GL_LINES); glColor3ub(80,0,0); glVertex3f(pos.X -1000, pos.Y -200, pos.Z); glVertex3f(pos.X +1000, pos.Y -200, pos.Z); glVertex3f(pos.X -1000, pos.Y +200, pos.Z); glVertex3f(pos.X +1000, pos.Y +200, pos.Z); glVertex3f(pos.X -200, pos.Y -1000, pos.Z); glVertex3f(pos.X -200, pos.Y +1000, pos.Z); glVertex3f(pos.X +200, pos.Y -1000, pos.Z); glVertex3f(pos.X +200, pos.Y +1000, pos.Z); glEnd(); }
And its header :
#ifndef KINECTDISPLAY_H #define KINECTDISPLAY_H
#include <GL/glut.h>
#include "myglwidget.h" class KinectDisplay : public myGLWidget { Q_OBJECT public: explicit KinectDisplay(QGLWidget *parent = 0, char *name = 0); void initializeGL(); void resizeGL(int width, int height); void paintGL(); }; #endif // KINECTDISPLAY_H
myglwidget.cpp :
#include "myglwidget.h" #include "ui_myglwidget.h" myGLWidget::myGLWidget(int framesPerSecond, QGLWidget *parent, char *name) : QGLWidget(parent) { setWindowTitle(QString::fromUtf8(name)); if(framesPerSecond == 0) t_Timer = NULL; else { int seconde = 1000; // 1 seconde = 1000 ms int timerInterval = seconde / framesPerSecond; t_Timer = new QTimer(this); connect(t_Timer, SIGNAL(timeout()), this, SLOT(updateGL())); t_Timer->start( timerInterval ); } } void myGLWidget::updateGL() { QGLWidget::updateGL(); }
And myglwidget.h:
#ifndef MYGLWIDGET_H #define MYGLWIDGET_H #include <QtOpenGL> #include <QGLWidget> class myGLWidget : public QGLWidget { Q_OBJECT public: explicit myGLWidget(int framesPerSecond = 0, QGLWidget *parent = 0, char *name = 0); virtual void initializeGL() = 0; virtual void resizeGL(int width, int height) = 0; virtual void paintGL() = 0; public slots: void updateGL(); private: QTimer *t_Timer; }; #endif // MYGLWIDGET_H
So here is the problem. When I did this, I just wanted to draw the lines. But I thought that at each frame, it draws the lines, and at each new frame, the old lines are not paint again. So I always have 4 lines drown and no more. But at each frame, it draws new lines so I have 4, 8, 12, 16, ... lines ...
If you have an answer :)..
Thank you
-
You are not clearing previous frame before painting the new one. At the start of your
paintGL()
method call this:glClear(GL_COLOR_BUFFER_BIT);
-
@Chris-Kawa said:
glClear(GL_COLOR_BUFFER_BIT);
Thank you very much ! You also solved another problem that seemed obscure !