tags:

views:

793

answers:

1

I'm triying to make a 2D real-time plot. I've tried with modifying the osciloscope example of qwt, tried to use QGraphicsView, and QPainter to reach high framerate drawing. I'm using 8 channels to plot data wich is arriving from a rs232 port. I take a sample every 10 ms. Maybe i've used the QPainter in a wrong way, but i couldn't draw very fast. With the qwt example, in wich doesn't update the whole screen the drawing speed was good, especially in X11 with Qt::WA_PaintOutsidePaintEvent and Qt::WA_PaintOnScreen.

Now i'm subclassing the QGLWidget, and i'm reaching a acceptable speed. But i'm wondering if i could improve it.

Every time I recived a new point i stored it, and the call updateGL(); In this case i recived only the y coordinate, buth i'm going to recive 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 reach the end of the screen, if is True i erase the screen if not, i draw only the the 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've disabled the Dithering and multisampling, and i'm using flat shades. i'm using an ortographic projection.

is there some way to draw faster? maybe using opengl for off-screen drawing and the showing the corresponding pixmap? is the a project similar to this?

+1  A: 

Vertex buffer objects (and perhaps display lists) would help this. Basically you need a way of reducing the number of GL calls you make, and it'll get fast.

Jay Kominek
i've just tried using vertex array and it's a bit faster.Now i'm going to take a look to display lists, and VBO (it's kind of a complex thing, isn't it? )
Luciano Lorenti
Yeah, they're not quite as simple as what you've got now.Also, it occurs to me that you should probably just treat your points array as a circular buffer, and redraw the whole thing every time DrawGL is invoked. That'll keep it as simple as possible, and should look identical. (probably even better; you'll get less flickering on the right hand side of the screen.)
Jay Kominek
I've made an attempt to clear the whole scene and redrawing all the scene in every drawGl, but it's turn really slow. But, i don't know, i'm redrawing 8 widgets, with at least 800 point each one. The Dublebuffering make it worst. I'm, for sure, doing something wrong. With a SingleBuffer and drawing only the last part of the curve I get and semi-acecptable speed :Smaybe making 1 widget with 8 lines?
Luciano Lorenti