PDA

View Full Version : Using QGLWidget for plotting



llemes4011
27th July 2010, 20:11
Hi, I'm using the QGLWidget to display some data that I'm trying to plot. Each graph has its own Y axis and they all share an X axis (also QGLWidgets) When I try to update my scales to match the data, my program locks up and starts running at 99% of the CPU. I have a signal/slot connection to pass the new min and max for the scale. It's watching a realtime data stream, and sampling at 20ms intervals, and redrawing the screen at 200ms intervals. When I redraw the screen, I want the scales to adjust to the new right bound of the graph. I have the following code:



// shifts the shared X axis
// This is a slot
void GLScaleWidget::shiftX(const double &amt){
this->min = amt;
this->max = amt+30; //(assume 30s of data for now)
this->makeCurrent();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslated(amt, 0, 0);
this->updateGL();
}


and the problem that I'm getting is that as soon as it starts to do any shifting on the scale, everything else dies too. (It works fine if i dont shift the scale) gl Calls stop functioning correctly, and everything goes black in the window.

Any help with this would be greatly appreciated.
Thanks!!!

agathiyaa
28th July 2010, 15:01
Why are you resetting the projection matrix before transformation ?:confused:

llemes4011
28th July 2010, 15:08
Thanks for the response =)

I'm resetting teh projection matrix because "amt" is the offset from x=0. I could save it and just subtract out the old amount from the new amount, and then transform it, but then there would be one more variable to deal with, and one more operation, and just as much matrix math lol. and doing it that way has reliably worked for me before haha

agathiyaa
28th July 2010, 15:27
If you comment these lines....
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

1. will gl Calls work ? and your graphics is OK(not black ) ?

Why dont you debug and find exactly where the problem is ?

llemes4011
28th July 2010, 15:40
it does the same thing - works up until I try to shift everything, and then fails in the same fashion... I've already started a class that does a similar job, but contains all of the code to draw the scales and the plots. and then just move around the scene using translatef(). I looked into it yesterday, and it seems like its due to the correct QGLContext not being active. I've also tried calling "makeCurrent()" before making gl calls in a class other than the one with the active QGLContext, but that didn't help either....