I am going to make a 2D plot in real time. I tried changing the qwt osciloscope example, tried using QGraphicsView and QPainter to achieve a high frame selection graph. I use 8 channels to build the data that comes from the rs232 port. I take a sample every 10 ms. Perhaps I used QPainter incorrectly, but I could not draw very quickly. With the qwt example, which does not refresh the entire screen, the drawing speed was good, especially in X11 with Qt :: WA_PaintOutsidePaintEvent and Qt :: WA_PaintOnScreen.
Now I am subclassing QGLWidget and I am achieving acceptable speed. But I wonder if I can improve it.
Every time I return a new point, I saved it, and call updateGL (); In this case, I only got the y coordinate, but I'm going to return the whole pair.
void Plot::addPoint(int y)
{
points[t].x=t;
points[t].y=y;
t++;
updateGL();
}
In DrawGL (), I check if the line reaches the end of the screen, if True, I erase the screen if not, I draw only a new part of the line.
glBegin(GL_LINES);
glVertex2i( points[t-1].x, points[t-1].y);
glVertex2i( points[t-2].x, points[t-2].y);
glEnd();
I turned off Dithering and multisampling, and I use flat shades. I use orthographic projection.
Is there any way to do it faster? perhaps using opengl for an off-screen drawing and showing the corresponding pixmap? is it a project like this?
source
share